Skip to content

Commit dadfe47

Browse files
committed
update select props
1 parent 05702c6 commit dadfe47

File tree

2 files changed

+79
-27
lines changed

2 files changed

+79
-27
lines changed

reflex_ui/components/base/select.py

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,46 @@ class SelectRoot(SelectBaseComponent):
6161

6262
# The uncontrolled value of the select when it's initially rendered.
6363
# To render a controlled select, use the `value` prop instead.
64-
default_value: Var[str]
64+
default_value: Var[Any]
6565

6666
# The value of the select
67-
value: Var[str]
67+
value: Var[Any]
6868

6969
# Callback fired when the value of the select changes. Use when controlled.
7070
on_value_change: EventHandler[passthrough_event_spec(str)]
7171

72-
# Whether the select menu is initially open.
73-
# To render a controlled select menu, use the `open` prop instead.
72+
# Whether the select popup is initially open.
73+
# To render a controlled select popup, use the `open` prop instead.
7474
default_open: Var[bool]
7575

76-
# Whether the select menu is currently open
76+
# Whether the select popup is currently open
7777
open: Var[bool]
7878

79-
# Event handler called when the select menu is opened or closed
79+
# Event handler called when the select popup is opened or closed
8080
on_open_change: EventHandler[passthrough_event_spec(bool)]
8181

82-
# Event handler called after any animations complete when the select menu is opened or closed
83-
on_open_change_complete: EventHandler[passthrough_event_spec(bool)]
82+
# A ref to imperative actions.
83+
# When specified, the select will not be unmounted when closed.
84+
# Instead, the `unmount` function must be called to unmount the select manually.
85+
# Useful when the select's animation is controlled by an external library.
86+
actions_ref: Var[str]
87+
88+
# Custom comparison logic used to determine if a select item value matches the current selected value.
89+
# Useful when item values are objects without matching referentially.
90+
# Defaults to `Object.is` comparison.
91+
is_item_equal_to_value: Var[Any]
92+
93+
# When the item values are objects, this function converts the object value to a string representation for display in the trigger.
94+
# If the shape of the object is `{ value, label }`, the label will be used automatically without needing to specify this prop.
95+
item_to_string_label: Var[Any]
96+
97+
# When the item values are objects, this function converts the object value to a string representation for form submission.
98+
# If the shape of the object is `{ value, label }`, the value will be used automatically without needing to specify this prop.
99+
item_to_string_value: Var[Any]
100+
101+
# Data structure of the items rendered in the select popup.
102+
# When specified, `<Select.Value>` renders the label of the selected item instead of the raw value.
103+
items: Var[Any]
84104

85105
# Determines if the select enters a modal state when open.
86106
# - True: user interaction is limited to the select: document page scroll is locked and pointer interactions on outside elements are disabled.
@@ -90,15 +110,21 @@ class SelectRoot(SelectBaseComponent):
90110
# Whether multiple items can be selected. Defaults to False.
91111
multiple: Var[bool]
92112

113+
# Event handler called after any animations complete when the select popup is opened or closed
114+
on_open_change_complete: EventHandler[passthrough_event_spec(bool)]
115+
93116
# Whether the component should ignore user interaction. Defaults to False.
94117
disabled: Var[bool]
95118

96-
# Whether the user should be unable to choose a different option from the select menu. Defaults to False.
119+
# Whether the user should be unable to choose a different option from the select popup. Defaults to False.
97120
read_only: Var[bool]
98121

99122
# Whether the user must choose a value before submitting a form. Defaults to False.
100123
required: Var[bool]
101124

125+
# A ref to access the hidden input element.
126+
input_ref: Var[Any]
127+
102128
@classmethod
103129
def create(cls, *children, **props) -> BaseUIComponent:
104130
"""Create the select root component."""

reflex_ui/components/base/select.pyi

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,21 @@ class SelectRoot(SelectBaseComponent):
9494
cls,
9595
*children,
9696
name: Var[str] | str | None = None,
97-
default_value: Var[str] | str | None = None,
98-
value: Var[str] | str | None = None,
97+
default_value: Any | Var[Any] | None = None,
98+
value: Any | Var[Any] | None = None,
9999
default_open: Var[bool] | bool | None = None,
100100
open: Var[bool] | bool | None = None,
101+
actions_ref: Var[str] | str | None = None,
102+
is_item_equal_to_value: Any | Var[Any] | None = None,
103+
item_to_string_label: Any | Var[Any] | None = None,
104+
item_to_string_value: Any | Var[Any] | None = None,
105+
items: Any | Var[Any] | None = None,
101106
modal: Var[bool] | bool | None = None,
102107
multiple: Var[bool] | bool | None = None,
103108
disabled: Var[bool] | bool | None = None,
104109
read_only: Var[bool] | bool | None = None,
105110
required: Var[bool] | bool | None = None,
111+
input_ref: Any | Var[Any] | None = None,
106112
unstyled: Var[bool] | bool | None = None,
107113
style: Sequence[Mapping[str, Any]]
108114
| Mapping[str, Any]
@@ -799,15 +805,20 @@ class HighLevelSelect(SelectRoot):
799805
| Var[Literal["lg", "md", "sm", "xl", "xs"]]
800806
| None = None,
801807
name: Var[str] | str | None = None,
802-
default_value: Var[str] | str | None = None,
803-
value: Var[str] | str | None = None,
808+
default_value: Any | Var[Any] | None = None,
809+
value: Any | Var[Any] | None = None,
804810
default_open: Var[bool] | bool | None = None,
805811
open: Var[bool] | bool | None = None,
812+
actions_ref: Var[str] | str | None = None,
813+
is_item_equal_to_value: Any | Var[Any] | None = None,
814+
item_to_string_label: Any | Var[Any] | None = None,
815+
item_to_string_value: Any | Var[Any] | None = None,
806816
modal: Var[bool] | bool | None = None,
807817
multiple: Var[bool] | bool | None = None,
808818
disabled: Var[bool] | bool | None = None,
809819
read_only: Var[bool] | bool | None = None,
810820
required: Var[bool] | bool | None = None,
821+
input_ref: Any | Var[Any] | None = None,
811822
unstyled: Var[bool] | bool | None = None,
812823
style: Sequence[Mapping[str, Any]]
813824
| Mapping[str, Any]
@@ -844,22 +855,27 @@ class HighLevelSelect(SelectRoot):
844855
845856
Args:
846857
*children: Additional children to include in the select.
847-
items: The list of items to display in the select dropdown
858+
items: Data structure of the items rendered in the select popup. When specified, `<Select.Value>` renders the label of the selected item instead of the raw value.
848859
placeholder: The placeholder text to display when no item is selected
849860
size: The size of the select component. Defaults to "md".
850861
name: Identifies the field when a form is submitted.
851862
default_value: The uncontrolled value of the select when it's initially rendered. To render a controlled select, use the `value` prop instead.
852863
value: The value of the select
853864
on_value_change: Callback fired when the value of the select changes. Use when controlled.
854-
default_open: Whether the select menu is initially open. To render a controlled select menu, use the `open` prop instead.
855-
open: Whether the select menu is currently open
856-
on_open_change: Event handler called when the select menu is opened or closed
857-
on_open_change_complete: Event handler called after any animations complete when the select menu is opened or closed
865+
default_open: Whether the select popup is initially open. To render a controlled select popup, use the `open` prop instead.
866+
open: Whether the select popup is currently open
867+
on_open_change: Event handler called when the select popup is opened or closed
868+
actions_ref: A ref to imperative actions. When specified, the select will not be unmounted when closed. Instead, the `unmount` function must be called to unmount the select manually. Useful when the select's animation is controlled by an external library.
869+
is_item_equal_to_value: Custom comparison logic used to determine if a select item value matches the current selected value. Useful when item values are objects without matching referentially. Defaults to `Object.is` comparison.
870+
item_to_string_label: When the item values are objects, this function converts the object value to a string representation for display in the trigger. If the shape of the object is `{ value, label }`, the label will be used automatically without needing to specify this prop.
871+
item_to_string_value: When the item values are objects, this function converts the object value to a string representation for form submission. If the shape of the object is `{ value, label }`, the value will be used automatically without needing to specify this prop.
858872
modal: Determines if the select enters a modal state when open. - True: user interaction is limited to the select: document page scroll is locked and pointer interactions on outside elements are disabled. - False: user interaction with the rest of the document is allowed. Defaults to True.
859873
multiple: Whether multiple items can be selected. Defaults to False.
874+
on_open_change_complete: Event handler called after any animations complete when the select popup is opened or closed
860875
disabled: Whether the component should ignore user interaction. Defaults to False.
861-
read_only: Whether the user should be unable to choose a different option from the select menu. Defaults to False.
876+
read_only: Whether the user should be unable to choose a different option from the select popup. Defaults to False.
862877
required: Whether the user must choose a value before submitting a form. Defaults to False.
878+
input_ref: A ref to access the hidden input element.
863879
unstyled: Whether the component should be unstyled
864880
style: The style of the component.
865881
key: A unique key for the component.
@@ -902,15 +918,20 @@ class Select(ComponentNamespace):
902918
| Var[Literal["lg", "md", "sm", "xl", "xs"]]
903919
| None = None,
904920
name: Var[str] | str | None = None,
905-
default_value: Var[str] | str | None = None,
906-
value: Var[str] | str | None = None,
921+
default_value: Any | Var[Any] | None = None,
922+
value: Any | Var[Any] | None = None,
907923
default_open: Var[bool] | bool | None = None,
908924
open: Var[bool] | bool | None = None,
925+
actions_ref: Var[str] | str | None = None,
926+
is_item_equal_to_value: Any | Var[Any] | None = None,
927+
item_to_string_label: Any | Var[Any] | None = None,
928+
item_to_string_value: Any | Var[Any] | None = None,
909929
modal: Var[bool] | bool | None = None,
910930
multiple: Var[bool] | bool | None = None,
911931
disabled: Var[bool] | bool | None = None,
912932
read_only: Var[bool] | bool | None = None,
913933
required: Var[bool] | bool | None = None,
934+
input_ref: Any | Var[Any] | None = None,
914935
unstyled: Var[bool] | bool | None = None,
915936
style: Sequence[Mapping[str, Any]]
916937
| Mapping[str, Any]
@@ -947,22 +968,27 @@ class Select(ComponentNamespace):
947968
948969
Args:
949970
*children: Additional children to include in the select.
950-
items: The list of items to display in the select dropdown
971+
items: Data structure of the items rendered in the select popup. When specified, `<Select.Value>` renders the label of the selected item instead of the raw value.
951972
placeholder: The placeholder text to display when no item is selected
952973
size: The size of the select component. Defaults to "md".
953974
name: Identifies the field when a form is submitted.
954975
default_value: The uncontrolled value of the select when it's initially rendered. To render a controlled select, use the `value` prop instead.
955976
value: The value of the select
956977
on_value_change: Callback fired when the value of the select changes. Use when controlled.
957-
default_open: Whether the select menu is initially open. To render a controlled select menu, use the `open` prop instead.
958-
open: Whether the select menu is currently open
959-
on_open_change: Event handler called when the select menu is opened or closed
960-
on_open_change_complete: Event handler called after any animations complete when the select menu is opened or closed
978+
default_open: Whether the select popup is initially open. To render a controlled select popup, use the `open` prop instead.
979+
open: Whether the select popup is currently open
980+
on_open_change: Event handler called when the select popup is opened or closed
981+
actions_ref: A ref to imperative actions. When specified, the select will not be unmounted when closed. Instead, the `unmount` function must be called to unmount the select manually. Useful when the select's animation is controlled by an external library.
982+
is_item_equal_to_value: Custom comparison logic used to determine if a select item value matches the current selected value. Useful when item values are objects without matching referentially. Defaults to `Object.is` comparison.
983+
item_to_string_label: When the item values are objects, this function converts the object value to a string representation for display in the trigger. If the shape of the object is `{ value, label }`, the label will be used automatically without needing to specify this prop.
984+
item_to_string_value: When the item values are objects, this function converts the object value to a string representation for form submission. If the shape of the object is `{ value, label }`, the value will be used automatically without needing to specify this prop.
961985
modal: Determines if the select enters a modal state when open. - True: user interaction is limited to the select: document page scroll is locked and pointer interactions on outside elements are disabled. - False: user interaction with the rest of the document is allowed. Defaults to True.
962986
multiple: Whether multiple items can be selected. Defaults to False.
987+
on_open_change_complete: Event handler called after any animations complete when the select popup is opened or closed
963988
disabled: Whether the component should ignore user interaction. Defaults to False.
964-
read_only: Whether the user should be unable to choose a different option from the select menu. Defaults to False.
989+
read_only: Whether the user should be unable to choose a different option from the select popup. Defaults to False.
965990
required: Whether the user must choose a value before submitting a form. Defaults to False.
991+
input_ref: A ref to access the hidden input element.
966992
unstyled: Whether the component should be unstyled
967993
style: The style of the component.
968994
key: A unique key for the component.

0 commit comments

Comments
 (0)