Skip to content

Commit 62856f0

Browse files
committed
feat: Add update_on parameter to ui.input_{text,text_area,numeric,password}
1 parent 268950a commit 62856f0

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

shiny/ui/_input_numeric.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__all__ = ("input_numeric",)
22

3-
from typing import Optional
3+
from typing import Literal, Optional
44

55
from htmltools import Tag, TagChild, css, div, tags
66

@@ -19,6 +19,7 @@ def input_numeric(
1919
max: Optional[float] = None,
2020
step: Optional[float] = None,
2121
width: Optional[str] = None,
22+
update_on: Literal["change", "blur"] = "change",
2223
) -> Tag:
2324
"""
2425
Create an input control for entry of numeric values.
@@ -39,6 +40,11 @@ def input_numeric(
3940
Interval to use when stepping between min and max.
4041
width
4142
The CSS width, e.g. '400px', or '100%'
43+
update_on
44+
When should the input value be updated? Options are `"change"` (default) and
45+
`"blur"`. Use `"change"` to update the input immediately whenever the value
46+
changes. Use `"blur"`to delay the input update until the input loses focus (the
47+
user moves away from the input), or when Enter is pressed.
4248
4349
Returns
4450
-------
@@ -67,6 +73,7 @@ def input_numeric(
6773
min=min,
6874
max=max,
6975
step=step,
76+
data_update_on=update_on,
7077
),
7178
class_="form-group shiny-input-container",
7279
style=css(width=width),

shiny/ui/_input_password.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__all__ = ("input_password",)
22

3-
from typing import Optional
3+
from typing import Literal, Optional
44

55
from htmltools import Tag, TagChild, css, div, tags
66

@@ -17,6 +17,7 @@ def input_password(
1717
*,
1818
width: Optional[str] = None,
1919
placeholder: Optional[str] = None,
20+
update_on: Literal["change", "blur"] = "change",
2021
) -> Tag:
2122
"""
2223
Create an password control for entry of passwords.
@@ -33,6 +34,11 @@ def input_password(
3334
The CSS width, e.g., '400px', or '100%'.
3435
placeholder
3536
The placeholder of the input.
37+
update_on
38+
When should the input value be updated? Options are `"change"` (default) and
39+
`"blur"`. Use `"change"` to update the input immediately whenever the value
40+
changes. Use `"blur"`to delay the input update until the input loses focus (the
41+
user moves away from the input), or when Enter is pressed.
3642
3743
Returns
3844
-------
@@ -58,6 +64,7 @@ def input_password(
5864
value=value,
5965
class_="shiny-input-password form-control",
6066
placeholder=placeholder,
67+
data_update_on=update_on,
6168
),
6269
class_="form-group shiny-input-container",
6370
style=css(width=width),

shiny/ui/_input_text.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def input_text(
2020
placeholder: Optional[str] = None,
2121
autocomplete: Optional[str] = "off",
2222
spellcheck: Optional[Literal["true", "false"]] = None,
23+
update_on: Literal["change", "blur"] = "change",
2324
) -> Tag:
2425
"""
2526
Create an input control for entry of text values.
@@ -45,6 +46,11 @@ def input_text(
4546
spellcheck
4647
Whether to enable browser spell checking of the text input (default is ``None``). If
4748
None, then it will use the browser's default behavior.
49+
update_on
50+
When should the input value be updated? Options are `"change"` (default) and
51+
`"blur"`. Use `"change"` to update the input immediately whenever the value
52+
changes. Use `"blur"`to delay the input update until the input loses focus (the
53+
user moves away from the input), or when Enter is pressed.
4854
4955
Returns
5056
-------
@@ -74,6 +80,7 @@ def input_text(
7480
placeholder=placeholder,
7581
autocomplete=autocomplete,
7682
spellcheck=spellcheck,
83+
data_update_on=update_on,
7784
),
7885
class_="form-group shiny-input-container",
7986
style=css(width=width),
@@ -95,6 +102,7 @@ def input_text_area(
95102
autoresize: bool = False,
96103
autocomplete: Optional[str] = None,
97104
spellcheck: Optional[Literal["true", "false"]] = None,
105+
update_on: Literal["change", "blur"] = "change",
98106
) -> Tag:
99107
"""
100108
Create a textarea input control for entry of unstructured text values.
@@ -137,6 +145,11 @@ def input_text_area(
137145
spellcheck
138146
Whether to enable browser spell checking of the text input (default is ``None``). If
139147
None, then it will use the browser's default behavior.
148+
update_on
149+
When should the input value be updated? Options are `"change"` (default) and
150+
`"blur"`. Use `"change"` to update the input immediately whenever the value
151+
changes. Use `"blur"`to delay the input update until the input loses focus (the
152+
user moves away from the input), or when Ctrl/Cmd + Enter is pressed.
140153
141154
Returns
142155
-------
@@ -176,6 +189,7 @@ def input_text_area(
176189
cols=cols,
177190
autocomplete=autocomplete,
178191
spellcheck=spellcheck,
192+
data_update_on=update_on,
179193
)
180194

181195
return div(

tests/playwright/shiny/inputs/input_text_update_on/app.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,13 @@ def _():
134134

135135
app_ui = ui.page_fluid(
136136
ui.row(
137-
ui.column(6, ui.div({"class": "col-sm-12"}, text_input_ui("change"))),
138-
ui.column(6, ui.div({"class": "col-sm-12"}, text_input_ui("blur"))),
137+
ui.column(
138+
6,
139+
ui.div({"class": "col-sm-12"}, text_input_ui("change", update_on="change")),
140+
),
141+
ui.column(
142+
6, ui.div({"class": "col-sm-12"}, text_input_ui("blur", update_on="blur"))
143+
),
139144
)
140145
)
141146

0 commit comments

Comments
 (0)