Skip to content

Commit 814a8a6

Browse files
feat: support Optional[str] / optional for InputText
1 parent c5b47a8 commit 814a8a6

File tree

1 file changed

+55
-3
lines changed

1 file changed

+55
-3
lines changed

solara/components/input.py

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,61 @@ def cleanup():
3636
solara.use_effect(add_events, [enabled])
3737

3838

39+
@overload
3940
@solara.component
4041
def InputText(
4142
label: str,
4243
value: Union[str, solara.Reactive[str]] = "",
43-
on_value: Optional[Callable[[str], None]] = None,
44+
on_value: Optional[Callable[[str], None]] = ...,
45+
disabled: bool = ...,
46+
password: bool = ...,
47+
continuous_update: bool = ...,
48+
update_events: list = ...,
49+
error: Union[bool, str] = ...,
50+
message: Optional[str] = ...,
51+
classes: List[str] = ...,
52+
style: Optional[Union[str, Dict[str, str]]] = ...,
53+
autofocus: bool = ...,
54+
dense: bool = ...,
55+
hide_details: Union[str, bool] = ...,
56+
placeholder: Optional[str] = ...,
57+
prefix: Optional[str] = ...,
58+
suffix: Optional[str] = ...,
59+
clearable: Literal[False] = ...,
60+
optional: Literal[False] = ...,
61+
) -> reacton.core.ValueElement[vw.TextField, Any]: ...
62+
63+
64+
@overload
65+
@solara.component
66+
def InputText(
67+
label: str,
68+
value: Union[Optional[str], solara.Reactive[Optional[str]]] = ...,
69+
on_value: Optional[Callable[[Optional[str]], None]] = ...,
70+
disabled: bool = ...,
71+
password: bool = ...,
72+
continuous_update: bool = ...,
73+
update_events: list = ...,
74+
error: Union[bool, str] = ...,
75+
message: Optional[str] = ...,
76+
classes: List[str] = ...,
77+
style: Optional[Union[str, Dict[str, str]]] = ...,
78+
autofocus: bool = ...,
79+
dense: bool = ...,
80+
hide_details: Union[str, bool] = ...,
81+
placeholder: Optional[str] = ...,
82+
prefix: Optional[str] = ...,
83+
suffix: Optional[str] = ...,
84+
clearable: bool = ...,
85+
optional: Literal[True] = ...,
86+
) -> reacton.core.ValueElement[vw.TextField, Any]: ...
87+
88+
89+
@solara.component
90+
def InputText(
91+
label: str,
92+
value: Union[None, str, solara.Reactive[str], solara.Reactive[Optional[str]]] = "",
93+
on_value: Union[None, Callable[[Optional[str]], None], Callable[[str], None]] = None,
4494
disabled: bool = False,
4595
password: bool = False,
4696
continuous_update: bool = False,
@@ -56,7 +106,8 @@ def InputText(
56106
prefix: Optional[str] = None,
57107
suffix: Optional[str] = None,
58108
clearable: bool = False,
59-
):
109+
optional: bool = False,
110+
) -> reacton.core.ValueElement[vw.TextField, Optional[str]]:
60111
"""Free form text input.
61112
62113
### Basic example:
@@ -119,8 +170,9 @@ def Page():
119170
* `prefix`: Displays prefix text.
120171
* `suffix`: Displays suffix text.
121172
* `clearable`: Whether the input can be cleared.
173+
* `optional`: Whether the value can be None. If `clearable=True`, `optional` is forced to True.
122174
"""
123-
reactive_value = solara.use_reactive(value, on_value)
175+
reactive_value = solara.use_reactive(value, on_value) # type: ignore
124176
del value, on_value
125177
style_flat = solara.util._flatten_style(style)
126178
classes_flat = solara.util._combine_classes(classes)

0 commit comments

Comments
 (0)