Browse Source

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
Masen Furer 10 months ago
parent
commit
0ed895cde7
2 changed files with 26 additions and 0 deletions
  1. 3 0
      reflex/components/core/debounce.py
  2. 23 0
      tests/components/core/test_debounce.py

+ 3 - 0
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(

+ 23 - 0
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(