extend rx.input allowed types (#3149)
This commit is contained in:
parent
ce2bd2286e
commit
0c0477cffb
@ -330,7 +330,7 @@ class Component(BaseComponent, ABC):
|
|||||||
if not types._issubclass(passed_type, expected_type):
|
if not types._issubclass(passed_type, expected_type):
|
||||||
value_name = value._var_name if isinstance(value, Var) else value
|
value_name = value._var_name if isinstance(value, Var) else value
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
f"Invalid var passed for prop {key}, expected type {expected_type}, got value {value_name} of type {passed_type}."
|
f"Invalid var passed for prop {type(self).__name__}.{key}, expected type {expected_type}, got value {value_name} of type {passed_type}."
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check if the key is an event trigger.
|
# Check if the key is an event trigger.
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
"""Wrapper around react-debounce-input."""
|
"""Wrapper around react-debounce-input."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any, Type
|
from typing import Any, Type, Union
|
||||||
|
|
||||||
from reflex.components.component import Component
|
from reflex.components.component import Component
|
||||||
from reflex.constants import EventTriggers
|
from reflex.constants import EventTriggers
|
||||||
@ -34,7 +35,7 @@ class DebounceInput(Component):
|
|||||||
force_notify_on_blur: Var[bool]
|
force_notify_on_blur: Var[bool]
|
||||||
|
|
||||||
# If provided, create a fully-controlled input
|
# If provided, create a fully-controlled input
|
||||||
value: Var[str]
|
value: Var[Union[str, int, float]]
|
||||||
|
|
||||||
# The ref to attach to the created input
|
# The ref to attach to the created input
|
||||||
input_ref: Var[str]
|
input_ref: Var[str]
|
||||||
|
@ -7,7 +7,7 @@ from typing import Any, Dict, Literal, Optional, Union, overload
|
|||||||
from reflex.vars import Var, BaseVar, ComputedVar
|
from reflex.vars import Var, BaseVar, ComputedVar
|
||||||
from reflex.event import EventChain, EventHandler, EventSpec
|
from reflex.event import EventChain, EventHandler, EventSpec
|
||||||
from reflex.style import Style
|
from reflex.style import Style
|
||||||
from typing import Any, Type
|
from typing import Any, Type, Union
|
||||||
from reflex.components.component import Component
|
from reflex.components.component import Component
|
||||||
from reflex.constants import EventTriggers
|
from reflex.constants import EventTriggers
|
||||||
from reflex.vars import Var, VarData
|
from reflex.vars import Var, VarData
|
||||||
@ -24,7 +24,9 @@ class DebounceInput(Component):
|
|||||||
debounce_timeout: Optional[Union[Var[int], int]] = None,
|
debounce_timeout: Optional[Union[Var[int], int]] = None,
|
||||||
force_notify_by_enter: Optional[Union[Var[bool], bool]] = None,
|
force_notify_by_enter: Optional[Union[Var[bool], bool]] = None,
|
||||||
force_notify_on_blur: Optional[Union[Var[bool], bool]] = None,
|
force_notify_on_blur: Optional[Union[Var[bool], bool]] = None,
|
||||||
value: Optional[Union[Var[str], str]] = None,
|
value: Optional[
|
||||||
|
Union[Var[Union[str, int, float]], Union[str, int, float]]
|
||||||
|
] = None,
|
||||||
input_ref: Optional[Union[Var[str], str]] = None,
|
input_ref: Optional[Union[Var[str], str]] = None,
|
||||||
element: Optional[Union[Var[Type[Component]], Type[Component]]] = None,
|
element: Optional[Union[Var[Type[Component]], Type[Component]]] = None,
|
||||||
style: Optional[Style] = None,
|
style: Optional[Style] = None,
|
||||||
|
@ -338,7 +338,7 @@ class Input(BaseHTML):
|
|||||||
use_map: Var[Union[str, int, bool]]
|
use_map: Var[Union[str, int, bool]]
|
||||||
|
|
||||||
# Value of the input
|
# Value of the input
|
||||||
value: Var[Union[str, int, bool]]
|
value: Var[Union[str, int, float]]
|
||||||
|
|
||||||
def get_event_triggers(self) -> Dict[str, Any]:
|
def get_event_triggers(self) -> Dict[str, Any]:
|
||||||
"""Get the event triggers that pass the component's value to the handler.
|
"""Get the event triggers that pass the component's value to the handler.
|
||||||
|
@ -662,7 +662,7 @@ class Input(BaseHTML):
|
|||||||
Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
||||||
] = None,
|
] = None,
|
||||||
value: Optional[
|
value: Optional[
|
||||||
Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
Union[Var[Union[str, int, float]], Union[str, int, float]]
|
||||||
] = None,
|
] = None,
|
||||||
access_key: Optional[
|
access_key: Optional[
|
||||||
Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""Interactive components provided by @radix-ui/themes."""
|
"""Interactive components provided by @radix-ui/themes."""
|
||||||
|
|
||||||
from typing import Any, Dict, Literal
|
from typing import Any, Dict, Literal, Union
|
||||||
|
|
||||||
from reflex.components import el
|
from reflex.components import el
|
||||||
from reflex.components.component import Component, ComponentNamespace
|
from reflex.components.component import Component, ComponentNamespace
|
||||||
@ -128,7 +128,7 @@ class Input(RadixThemesComponent):
|
|||||||
type: Var[str]
|
type: Var[str]
|
||||||
|
|
||||||
# Value of the input
|
# Value of the input
|
||||||
value: Var[str]
|
value: Var[Union[str, int, float]]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, **props):
|
def create(cls, **props):
|
||||||
|
@ -7,7 +7,7 @@ from typing import Any, Dict, Literal, Optional, Union, overload
|
|||||||
from reflex.vars import Var, BaseVar, ComputedVar
|
from reflex.vars import Var, BaseVar, ComputedVar
|
||||||
from reflex.event import EventChain, EventHandler, EventSpec
|
from reflex.event import EventChain, EventHandler, EventSpec
|
||||||
from reflex.style import Style
|
from reflex.style import Style
|
||||||
from typing import Any, Dict, Literal
|
from typing import Any, Dict, Literal, Union
|
||||||
from reflex.components import el
|
from reflex.components import el
|
||||||
from reflex.components.component import Component, ComponentNamespace
|
from reflex.components.component import Component, ComponentNamespace
|
||||||
from reflex.components.core.debounce import DebounceInput
|
from reflex.components.core.debounce import DebounceInput
|
||||||
@ -313,7 +313,7 @@ class TextFieldInput(el.Input, TextFieldRoot):
|
|||||||
Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
||||||
] = None,
|
] = None,
|
||||||
value: Optional[
|
value: Optional[
|
||||||
Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
Union[Var[Union[str, int, float]], Union[str, int, float]]
|
||||||
] = None,
|
] = None,
|
||||||
variant: Optional[
|
variant: Optional[
|
||||||
Union[
|
Union[
|
||||||
@ -796,7 +796,9 @@ class Input(RadixThemesComponent):
|
|||||||
read_only: Optional[Union[Var[bool], bool]] = None,
|
read_only: Optional[Union[Var[bool], bool]] = None,
|
||||||
required: Optional[Union[Var[bool], bool]] = None,
|
required: Optional[Union[Var[bool], bool]] = None,
|
||||||
type: Optional[Union[Var[str], str]] = None,
|
type: Optional[Union[Var[str], str]] = None,
|
||||||
value: Optional[Union[Var[str], str]] = None,
|
value: Optional[
|
||||||
|
Union[Var[Union[str, int, float]], Union[str, int, float]]
|
||||||
|
] = None,
|
||||||
style: Optional[Style] = None,
|
style: Optional[Style] = None,
|
||||||
key: Optional[Any] = None,
|
key: Optional[Any] = None,
|
||||||
id: Optional[Any] = None,
|
id: Optional[Any] = None,
|
||||||
@ -986,7 +988,9 @@ class TextField(ComponentNamespace):
|
|||||||
read_only: Optional[Union[Var[bool], bool]] = None,
|
read_only: Optional[Union[Var[bool], bool]] = None,
|
||||||
required: Optional[Union[Var[bool], bool]] = None,
|
required: Optional[Union[Var[bool], bool]] = None,
|
||||||
type: Optional[Union[Var[str], str]] = None,
|
type: Optional[Union[Var[str], str]] = None,
|
||||||
value: Optional[Union[Var[str], str]] = None,
|
value: Optional[
|
||||||
|
Union[Var[Union[str, int, float]], Union[str, int, float]]
|
||||||
|
] = None,
|
||||||
style: Optional[Style] = None,
|
style: Optional[Style] = None,
|
||||||
key: Optional[Any] = None,
|
key: Optional[Any] = None,
|
||||||
id: Optional[Any] = None,
|
id: Optional[Any] = None,
|
||||||
|
@ -1825,8 +1825,8 @@ class BaseVar(Var):
|
|||||||
value = self._var_type(value)
|
value = self._var_type(value)
|
||||||
setattr(state, self._var_name, value)
|
setattr(state, self._var_name, value)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
console.warn(
|
console.debug(
|
||||||
f"{self._var_name}: Failed conversion of {value} to '{self._var_type.__name__}'. Value not set.",
|
f"{type(state).__name__}.{self._var_name}: Failed conversion of {value} to '{self._var_type.__name__}'. Value not set.",
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
setattr(state, self._var_name, value)
|
setattr(state, self._var_name, value)
|
||||||
|
Loading…
Reference in New Issue
Block a user