From 0ed895cde71e41545992fded14e43fb371cbdfd2 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Fri, 12 Jul 2024 13:27:19 -0700 Subject: [PATCH] debounce: pass through key and special_props (#3655) These fields on the base Component were not being carried onto the DebounceInput component (to be passed to the child). Discovered while testing #3653 --- reflex/components/core/debounce.py | 3 +++ tests/components/core/test_debounce.py | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/reflex/components/core/debounce.py b/reflex/components/core/debounce.py index dca79b0f9..4dc7c14a1 100644 --- a/reflex/components/core/debounce.py +++ b/reflex/components/core/debounce.py @@ -101,6 +101,9 @@ class DebounceInput(Component): props.setdefault("style", {}).update(child.style) if child.class_name is not None: props["class_name"] = f"{props.get('class_name', '')} {child.class_name}" + for field in ("key", "special_props"): + if getattr(child, field) is not None: + props[field] = getattr(child, field) child_ref = child.get_ref() if props.get("input_ref") is None and child_ref: props["input_ref"] = Var.create_safe( diff --git a/tests/components/core/test_debounce.py b/tests/components/core/test_debounce.py index e4bcb05c4..8ad15ea58 100644 --- a/tests/components/core/test_debounce.py +++ b/tests/components/core/test_debounce.py @@ -92,6 +92,29 @@ def test_render_with_ref(): assert "foo_bar" in str(tag.props["inputRef"]) +def test_render_with_key(): + tag = rx.debounce_input( + rx.input( + on_change=S.on_change, + key="foo_bar", + ) + )._render() + assert isinstance(tag.props["key"], rx.Var) + assert "foo_bar" in str(tag.props["key"]) + + +def test_render_with_special_props(): + special_prop = rx.Var.create_safe("{foo_bar}", _var_is_string=False) + tag = rx.debounce_input( + rx.input( + on_change=S.on_change, + special_props=[special_prop], + ) + )._render() + assert len(tag.special_props) == 1 + assert list(tag.special_props)[0].equals(special_prop) + + def test_event_triggers(): debounced_input = rx.debounce_input( rx.input(