Skip to content

Commit

Permalink
[REF-2101] Support default_value and default_checked on rx.el.input (r…
Browse files Browse the repository at this point in the history
  • Loading branch information
masenf authored Feb 28, 2024
1 parent deae662 commit 3c3c331
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
48 changes: 42 additions & 6 deletions integration/test_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,33 @@ class State(rx.State):
@app.add_page
def index():
return rx.fragment(
rx.chakra.input(
rx.input(
value=State.router.session.client_token, is_read_only=True, id="token"
),
rx.chakra.input(
rx.input(
id="debounce_input_input",
on_change=State.set_text, # type: ignore
value=State.text,
),
rx.chakra.input(value=State.text, id="value_input", is_read_only=True),
rx.chakra.input(on_change=State.set_text, id="on_change_input"), # type: ignore
rx.input(value=State.text, id="value_input", is_read_only=True),
rx.input(on_change=State.set_text, id="on_change_input"), # type: ignore
rx.el.input(
value=State.text,
id="plain_value_input",
disabled=True,
_disabled={"background_color": "#EEE"},
),
rx.button("CLEAR", on_click=rx.set_value("on_change_input", "")),
rx.input(default_value="default", id="default_input"),
rx.el.input(
type="text", default_value="default plain", id="plain_default_input"
),
rx.checkbox(default_checked=True, id="default_checkbox"),
rx.el.input(
type="checkbox", default_checked=True, id="plain_default_checkbox"
),
rx.button(
"CLEAR", on_click=rx.set_value("on_change_input", ""), id="clear"
),
)


Expand Down Expand Up @@ -79,12 +89,38 @@ async def get_state_text():
state = await fully_controlled_input.get_state(f"{token}_state.state")
return state.substates["state"].text

# ensure defaults are set correctly
assert (
fully_controlled_input.poll_for_value(
driver.find_element(By.ID, "default_input")
)
== "default"
)
assert (
fully_controlled_input.poll_for_value(
driver.find_element(By.ID, "plain_default_input")
)
== "default plain"
)
assert (
fully_controlled_input.poll_for_value(
driver.find_element(By.ID, "default_checkbox")
)
== "on"
)
assert (
fully_controlled_input.poll_for_value(
driver.find_element(By.ID, "plain_default_checkbox")
)
== "on"
)

# find the input and wait for it to have the initial state value
debounce_input = driver.find_element(By.ID, "debounce_input_input")
value_input = driver.find_element(By.ID, "value_input")
on_change_input = driver.find_element(By.ID, "on_change_input")
plain_value_input = driver.find_element(By.ID, "plain_value_input")
clear_button = driver.find_element(By.TAG_NAME, "button")
clear_button = driver.find_element(By.ID, "clear")
assert fully_controlled_input.poll_for_value(debounce_input) == "initial"
assert fully_controlled_input.poll_for_value(value_input) == "initial"
assert fully_controlled_input.poll_for_value(plain_value_input) == "initial"
Expand Down
6 changes: 6 additions & 0 deletions reflex/components/el/elements/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ class Input(BaseHTML):
# Indicates whether the input is checked (for checkboxes and radio buttons)
checked: Var[Union[str, int, bool]]

# The initial value (for checkboxes and radio buttons)
default_checked: Var[bool]

# The initial value for a text field
default_value: Var[str]

# Name part of the input to submit in 'dir' and 'name' pair when form is submitted
dirname: Var[Union[str, int, bool]]

Expand Down
4 changes: 4 additions & 0 deletions reflex/components/el/elements/forms.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,8 @@ class Input(BaseHTML):
checked: Optional[
Union[Var[Union[str, int, bool]], Union[str, int, bool]]
] = None,
default_checked: Optional[Union[Var[bool], bool]] = None,
default_value: Optional[Union[Var[str], str]] = None,
dirname: Optional[
Union[Var[Union[str, int, bool]], Union[str, int, bool]]
] = None,
Expand Down Expand Up @@ -767,6 +769,8 @@ class Input(BaseHTML):
auto_focus: Automatically focuses the input when the page loads
capture: Captures media from the user (camera or microphone)
checked: Indicates whether the input is checked (for checkboxes and radio buttons)
default_checked: The initial value (for checkboxes and radio buttons)
default_value: The initial value for a text field
dirname: Name part of the input to submit in 'dir' and 'name' pair when form is submitted
disabled: Disables the input
form: Associates the input with a form (by id)
Expand Down
4 changes: 4 additions & 0 deletions reflex/components/radix/themes/components/text_field.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ class TextFieldInput(el.Input, TextFieldRoot):
checked: Optional[
Union[Var[Union[str, int, bool]], Union[str, int, bool]]
] = None,
default_checked: Optional[Union[Var[bool], bool]] = None,
default_value: Optional[Union[Var[str], str]] = None,
dirname: Optional[
Union[Var[Union[str, int, bool]], Union[str, int, bool]]
] = None,
Expand Down Expand Up @@ -499,6 +501,8 @@ class TextFieldInput(el.Input, TextFieldRoot):
auto_focus: Automatically focuses the input when the page loads
capture: Captures media from the user (camera or microphone)
checked: Indicates whether the input is checked (for checkboxes and radio buttons)
default_checked: The initial value (for checkboxes and radio buttons)
default_value: The initial value for a text field
dirname: Name part of the input to submit in 'dir' and 'name' pair when form is submitted
disabled: Disables the input
form: Associates the input with a form (by id)
Expand Down

0 comments on commit 3c3c331

Please sign in to comment.