diff --git a/solara/components/select.py b/solara/components/select.py index df7dfe21f..34cc9b9e1 100644 --- a/solara/components/select.py +++ b/solara/components/select.py @@ -17,6 +17,7 @@ def Select( value: None = ..., on_value: Optional[Callable[[Optional[T]], None]] = ..., dense: bool = ..., + disabled: bool = ..., classes: List[str] = [], style: Union[str, Dict[str, str], None] = None, ) -> reacton.core.ValueElement[v.Select, T]: @@ -30,6 +31,7 @@ def Select( value: T = ..., on_value: Optional[Callable[[T], None]] = ..., dense: bool = ..., + disabled: bool = ..., classes: List[str] = [], style: Union[str, Dict[str, str], None] = None, ) -> reacton.core.ValueElement[v.Select, T]: @@ -43,6 +45,7 @@ def Select( value: solara.Reactive[Optional[T]] = ..., on_value: Optional[Callable[[Optional[T]], None]] = ..., dense: bool = ..., + disabled: bool = ..., classes: List[str] = [], style: Union[str, Dict[str, str], None] = None, ) -> reacton.core.ValueElement[v.Select, T]: @@ -56,6 +59,7 @@ def Select( value: solara.Reactive[T] = ..., on_value: Optional[Callable[[T], None]] = None, dense: bool = ..., + disabled: bool = ..., classes: List[str] = [], style: Union[str, Dict[str, str], None] = None, ) -> reacton.core.ValueElement[v.Select, T]: @@ -69,6 +73,7 @@ def Select( value: Union[None, T, solara.Reactive[T], solara.Reactive[Optional[T]]] = None, on_value: Union[None, Callable[[T], None], Callable[[Optional[T]], None]] = None, dense: bool = False, + disabled: bool = False, classes: List[str] = [], style: Union[str, Dict[str, str], None] = None, ) -> reacton.core.ValueElement[v.Select, T]: @@ -96,6 +101,7 @@ def Page(): * `values`: List of values to select from. * `on_value`: Callback to call when the value changes. * `dense`: Whether to use a denser style. + * `disabled`: Whether the select widget allow user interaction * `classes`: List of CSS classes to apply to the select. * `style`: CSS style to apply to the select. @@ -114,6 +120,7 @@ def Page(): items=values, label=label, dense=dense, + disabled=disabled, class_=class_, style_=style_flat, ), @@ -127,6 +134,7 @@ def SelectMultiple( all_values: List[T], on_value: Callable[[List[T]], None] = None, dense: bool = False, + disabled: bool = False, classes: List[str] = [], style: Union[str, Dict[str, str], None] = None, ) -> reacton.core.ValueElement[v.Select, List[T]]: @@ -154,6 +162,7 @@ def Page(): * `all_values`: List of all values to select from. * `on_value`: Callback to call when the value changes. * `dense`: Whether to use a denser style. + * `disabled`: Whether the select widget allow user interaction * `classes`: List of CSS classes to apply to the select. * `style`: CSS style to apply to the select. """ @@ -170,6 +179,7 @@ def Page(): label=label, multiple=True, dense=False, + disabled=disabled, class_=class_, style_=style_flat, ), diff --git a/tests/unit/select_test.py b/tests/unit/select_test.py new file mode 100644 index 000000000..2e1d8e6b7 --- /dev/null +++ b/tests/unit/select_test.py @@ -0,0 +1,47 @@ +from unittest.mock import MagicMock + +import ipyvuetify as vw + +import solara + + +def test_select(): + """ + test select widget + """ + disabled = None + on_value = MagicMock() + on_value_multiple = MagicMock() + + @solara.component + def Test(): + nonlocal disabled + disabled = solara.use_reactive(False) + solara.Select(label="single", values=["test0", "test1", "test2"], on_value=on_value, disabled=disabled.value) + solara.SelectMultiple(label="multiple", values=[], all_values=["test0", "test1", "test2"], on_value=on_value_multiple, disabled=disabled.value) + + _, rc = solara.render(Test(), handle_error=False) + select = rc.find(vw.Select, label="single").widget + select_multi = rc.find(vw.Select, label="multiple").widget + + # init + assert not select.disabled + assert not select_multi.disabled + + assert select.v_model is None + assert select_multi.v_model == [] + + # set v_model + select.v_model = "test0" + assert on_value.call_count == 1 + assert on_value.call_args[0][0] == "test0" + + select_multi.v_model = ["test0", "test1"] + assert on_value_multiple.call_count == 1 + assert on_value_multiple.call_args[0][0] == ["test0", "test1"] + + # test disable + disabled.set(True) + assert len(rc.find(vw.Select, disabled=True).widgets) == 2 + + rc.close()