From 82dc237f449fd9696bcf619fd9706936ee09e2d5 Mon Sep 17 00:00:00 2001 From: Martin Xu <15661672+martinxu9@users.noreply.github.com> Date: Wed, 23 Aug 2023 17:16:03 -0700 Subject: [PATCH] Revert "Use DebounceInput wrapper for fully controlled Editable" (#1670) --- reflex/components/forms/editable.py | 25 ------------- tests/components/forms/test_editable.py | 48 ------------------------- 2 files changed, 73 deletions(-) delete mode 100644 tests/components/forms/test_editable.py diff --git a/reflex/components/forms/editable.py b/reflex/components/forms/editable.py index 1d0e303a4..cf004d2ff 100644 --- a/reflex/components/forms/editable.py +++ b/reflex/components/forms/editable.py @@ -2,8 +2,6 @@ from typing import Dict -from reflex.components.component import Component -from reflex.components.forms.debounce import DebounceInput from reflex.components.libs.chakra import ChakraComponent from reflex.event import EVENT_ARG from reflex.vars import Var @@ -38,29 +36,6 @@ class Editable(ChakraComponent): # The initial value of the Editable in both edit and preview mode. default_value: Var[str] - @classmethod - def create(cls, *children, **props) -> Component: - """Create an Editable component. - - Args: - children: The children of the component. - props: The properties of the component. - - Returns: - The component. - """ - if ( - isinstance(props.get("value"), Var) and props.get("on_change") - ) or "debounce_timeout" in props: - # Create a debounced input if the user requests full control to avoid typing jank - # Currently default to 50ms, which appears to be a good balance - debounce_timeout = props.pop("debounce_timeout", 50) - return DebounceInput.create( - super().create(*children, **props), - debounce_timeout=debounce_timeout, - ) - return super().create(*children, **props) - def get_controlled_triggers(self) -> Dict[str, Var]: """Get the event triggers that pass the component's value to the handler. diff --git a/tests/components/forms/test_editable.py b/tests/components/forms/test_editable.py deleted file mode 100644 index 833239a5e..000000000 --- a/tests/components/forms/test_editable.py +++ /dev/null @@ -1,48 +0,0 @@ -import reflex as rx - - -class S(rx.State): - """Example state for debounce tests.""" - - value: str = "" - - def on_change(self, v: str): - """Dummy on_change handler. - - Args: - v: The changed value. - """ - pass - - -def test_full_control_implicit_debounce_editable(): - """DebounceInput is used when value and on_change are used together.""" - tag = rx.editable( - value=S.value, - on_change=S.on_change, - )._render() - assert tag.props["debounceTimeout"].name == "50" - assert len(tag.props["onChange"].events) == 1 - assert tag.props["onChange"].events[0].handler == S.on_change - assert tag.contents == "" - - -def test_full_control_explicit_debounce_editable(): - """DebounceInput is used when user specifies `debounce_timeout`.""" - tag = rx.editable( - on_change=S.on_change, - debounce_timeout=33, - )._render() - assert tag.props["debounceTimeout"].name == "33" - assert len(tag.props["onChange"].events) == 1 - assert tag.props["onChange"].events[0].handler == S.on_change - assert tag.contents == "" - - -def test_editable_no_debounce(): - """DebounceInput is not used for regular editable.""" - tag = rx.editable( - placeholder=S.value, - )._render() - assert "debounceTimeout" not in tag.props - assert tag.contents == ""