From fe244b7eecac2d258effb62e8e11e3d6fd11f4a5 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Fri, 20 Oct 2023 09:43:46 -0700 Subject: [PATCH] multi_select somewhat usable (#1861) --- reflex/components/__init__.py | 2 +- reflex/components/forms/multiselect.py | 20 ++++++++++++-------- reflex/constants/installer.py | 1 - 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/reflex/components/__init__.py b/reflex/components/__init__.py index f9a580032..b4f44619e 100644 --- a/reflex/components/__init__.py +++ b/reflex/components/__init__.py @@ -113,7 +113,7 @@ input_left_addon = InputLeftAddon.create input_right_addon = InputRightAddon.create input_left_element = InputLeftElement.create input_right_element = InputRightElement.create -multi_select = MultiSelect +multi_select = MultiSelect.create multi_select_option = MultiSelectOption number_decrement_stepper = NumberDecrementStepper.create number_increment_stepper = NumberIncrementStepper.create diff --git a/reflex/components/forms/multiselect.py b/reflex/components/forms/multiselect.py index 453b21284..d9af42c3b 100644 --- a/reflex/components/forms/multiselect.py +++ b/reflex/components/forms/multiselect.py @@ -46,8 +46,9 @@ class Select(Component): Props added by chakra-react-select are marked with "[chakra]". """ - library = "chakra-react-select" + library = "chakra-react-select@4.7.5" tag = "Select" + alias = "MultiSelect" # Focus the control when it is mounted auto_focus: Var[bool] @@ -311,7 +312,7 @@ class Select(Component): lambda e0: [ Var.create_safe(f"{e0}.map(e => e.value)", _var_is_local=True) ] - if self.is_multi + if self.is_multi.equals(Var.create_safe(True)) else lambda e0: [e0] ), } @@ -341,10 +342,13 @@ class Select(Component): The `create` method is returning an instance of the `Select` class. """ converted_options: List[Option] = [] - for option in options: - if not isinstance(option, Option): - converted_options.append(Option(label=str(option), value=option)) - else: - converted_options.append(option) - props["options"] = [o.dict() for o in converted_options] + if not isinstance(options, Var): + for option in options: + if not isinstance(option, Option): + converted_options.append(Option(label=str(option), value=option)) + else: + converted_options.append(option) + props["options"] = [o.dict() for o in converted_options] + else: + props["options"] = options return super().create(*[], **props) diff --git a/reflex/constants/installer.py b/reflex/constants/installer.py index 87e453327..b39ecb78c 100644 --- a/reflex/constants/installer.py +++ b/reflex/constants/installer.py @@ -103,7 +103,6 @@ class PackageJson(SimpleNamespace): DEPENDENCIES = { "axios": "1.4.0", - "chakra-react-select": "4.6.0", "focus-visible": "5.2.0", "framer-motion": "10.16.4", "json5": "2.2.3",