1
0

textarea.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. """A textarea component."""
  2. from typing import Dict
  3. from reflex.components.component import EVENT_ARG, Component
  4. from reflex.components.forms.debounce import DebounceInput
  5. from reflex.components.libs.chakra import ChakraComponent
  6. from reflex.vars import Var
  7. class TextArea(ChakraComponent):
  8. """A text area component."""
  9. tag = "Textarea"
  10. # State var to bind the input.
  11. value: Var[str]
  12. # The default value of the textarea.
  13. default_value: Var[str]
  14. # The placeholder text.
  15. placeholder: Var[str]
  16. # The border color when the input is invalid.
  17. error_border_color: Var[str]
  18. # The border color when the input is focused.
  19. focus_border_color: Var[str]
  20. # If true, the form control will be disabled.
  21. is_disabled: Var[bool]
  22. # If true, the form control will be invalid.
  23. is_invalid: Var[bool]
  24. # If true, the form control will be read-only.
  25. is_read_only: Var[bool]
  26. # If true, the form control will be required.
  27. is_required: Var[bool]
  28. # "outline" | "filled" | "flushed" | "unstyled"
  29. variant: Var[str]
  30. def get_controlled_triggers(self) -> Dict[str, Var]:
  31. """Get the event triggers that pass the component's value to the handler.
  32. Returns:
  33. A dict mapping the event trigger to the var that is passed to the handler.
  34. """
  35. return {
  36. "on_change": EVENT_ARG.target.value,
  37. "on_focus": EVENT_ARG.target.value,
  38. "on_blur": EVENT_ARG.target.value,
  39. "on_key_down": EVENT_ARG.key,
  40. "on_key_up": EVENT_ARG.key,
  41. }
  42. @classmethod
  43. def create(cls, *children, **props) -> Component:
  44. """Create an Input component.
  45. Args:
  46. children: The children of the component.
  47. props: The properties of the component.
  48. Returns:
  49. The component.
  50. """
  51. if isinstance(props.get("value"), Var) and props.get("on_change"):
  52. # create a debounced input if the user requests full control to avoid typing jank
  53. return DebounceInput.create(
  54. super().create(*children, **props), debounce_timeout=0
  55. )
  56. return super().create(*children, **props)