textarea.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. """A textarea component."""
  2. from __future__ import annotations
  3. from reflex.components.chakra import ChakraComponent, LiteralInputVariant
  4. from reflex.components.component import Component
  5. from reflex.components.core.debounce import DebounceInput
  6. from reflex.event import EventHandler
  7. from reflex.vars import Var
  8. class TextArea(ChakraComponent):
  9. """A text area component."""
  10. tag = "Textarea"
  11. # State var to bind the input.
  12. value: Var[str]
  13. # The default value of the textarea.
  14. default_value: Var[str]
  15. # The placeholder text.
  16. placeholder: Var[str]
  17. # The border color when the input is invalid.
  18. error_border_color: Var[str]
  19. # The border color when the input is focused.
  20. focus_border_color: Var[str]
  21. # If true, the form control will be disabled.
  22. is_disabled: Var[bool]
  23. # If true, the form control will be invalid.
  24. is_invalid: Var[bool]
  25. # If true, the form control will be read-only.
  26. is_read_only: Var[bool]
  27. # If true, the form control will be required.
  28. is_required: Var[bool]
  29. # "outline" | "filled" | "flushed" | "unstyled"
  30. variant: Var[LiteralInputVariant]
  31. # The name of the form field
  32. name: Var[str]
  33. # Fired when the value changes.
  34. on_change: EventHandler[lambda e0: [e0.target.value]]
  35. # Fired when the textarea gets focus.
  36. on_focus: EventHandler[lambda e0: [e0.target.value]]
  37. # Fired when the textarea loses focus.
  38. on_blur: EventHandler[lambda e0: [e0.target.value]]
  39. # Fired when a key is pressed down.
  40. on_key_down: EventHandler[lambda e0: [e0.key]]
  41. # Fired when a key is released.
  42. on_key_up: EventHandler[lambda e0: [e0.key]]
  43. @classmethod
  44. def create(cls, *children, **props) -> Component:
  45. """Create an Input component.
  46. Args:
  47. *children: The children of the component.
  48. **props: The properties of the component.
  49. Returns:
  50. The component.
  51. """
  52. if props.get("value") is not None and props.get("on_change"):
  53. # create a debounced input if the user requests full control to avoid typing jank
  54. return DebounceInput.create(super().create(*children, **props))
  55. return super().create(*children, **props)