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):
|
||||
value_name = value._var_name if isinstance(value, Var) else value
|
||||
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.
|
||||
|
@ -1,7 +1,8 @@
|
||||
"""Wrapper around react-debounce-input."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Type
|
||||
from typing import Any, Type, Union
|
||||
|
||||
from reflex.components.component import Component
|
||||
from reflex.constants import EventTriggers
|
||||
@ -34,7 +35,7 @@ class DebounceInput(Component):
|
||||
force_notify_on_blur: Var[bool]
|
||||
|
||||
# If provided, create a fully-controlled input
|
||||
value: Var[str]
|
||||
value: Var[Union[str, int, float]]
|
||||
|
||||
# The ref to attach to the created input
|
||||
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.event import EventChain, EventHandler, EventSpec
|
||||
from reflex.style import Style
|
||||
from typing import Any, Type
|
||||
from typing import Any, Type, Union
|
||||
from reflex.components.component import Component
|
||||
from reflex.constants import EventTriggers
|
||||
from reflex.vars import Var, VarData
|
||||
@ -24,7 +24,9 @@ class DebounceInput(Component):
|
||||
debounce_timeout: Optional[Union[Var[int], int]] = None,
|
||||
force_notify_by_enter: 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,
|
||||
element: Optional[Union[Var[Type[Component]], Type[Component]]] = None,
|
||||
style: Optional[Style] = None,
|
||||
|
@ -338,7 +338,7 @@ class Input(BaseHTML):
|
||||
use_map: Var[Union[str, int, bool]]
|
||||
|
||||
# Value of the input
|
||||
value: Var[Union[str, int, bool]]
|
||||
value: Var[Union[str, int, float]]
|
||||
|
||||
def get_event_triggers(self) -> Dict[str, Any]:
|
||||
"""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]]
|
||||
] = None,
|
||||
value: Optional[
|
||||
Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
||||
Union[Var[Union[str, int, float]], Union[str, int, float]]
|
||||
] = None,
|
||||
access_key: Optional[
|
||||
Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
||||
|
@ -1,6 +1,6 @@
|
||||
"""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.component import Component, ComponentNamespace
|
||||
@ -128,7 +128,7 @@ class Input(RadixThemesComponent):
|
||||
type: Var[str]
|
||||
|
||||
# Value of the input
|
||||
value: Var[str]
|
||||
value: Var[Union[str, int, float]]
|
||||
|
||||
@classmethod
|
||||
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.event import EventChain, EventHandler, EventSpec
|
||||
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.component import Component, ComponentNamespace
|
||||
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]]
|
||||
] = None,
|
||||
value: Optional[
|
||||
Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
||||
Union[Var[Union[str, int, float]], Union[str, int, float]]
|
||||
] = None,
|
||||
variant: Optional[
|
||||
Union[
|
||||
@ -796,7 +796,9 @@ class Input(RadixThemesComponent):
|
||||
read_only: Optional[Union[Var[bool], bool]] = None,
|
||||
required: Optional[Union[Var[bool], bool]] = 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,
|
||||
key: Optional[Any] = None,
|
||||
id: Optional[Any] = None,
|
||||
@ -986,7 +988,9 @@ class TextField(ComponentNamespace):
|
||||
read_only: Optional[Union[Var[bool], bool]] = None,
|
||||
required: Optional[Union[Var[bool], bool]] = 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,
|
||||
key: Optional[Any] = None,
|
||||
id: Optional[Any] = None,
|
||||
|
@ -1825,8 +1825,8 @@ class BaseVar(Var):
|
||||
value = self._var_type(value)
|
||||
setattr(state, self._var_name, value)
|
||||
except ValueError:
|
||||
console.warn(
|
||||
f"{self._var_name}: Failed conversion of {value} to '{self._var_type.__name__}'. Value not set.",
|
||||
console.debug(
|
||||
f"{type(state).__name__}.{self._var_name}: Failed conversion of {value} to '{self._var_type.__name__}'. Value not set.",
|
||||
)
|
||||
else:
|
||||
setattr(state, self._var_name, value)
|
||||
|
Loading…
Reference in New Issue
Block a user