Class: Charming::Presentation::Components::TextInput
- Inherits:
-
Charming::Presentation::Component
- Object
- View
- Charming::Presentation::Component
- Charming::Presentation::Components::TextInput
- Includes:
- KeyboardHandler
- Defined in:
- lib/charming/presentation/components/text_input.rb
Constant Summary collapse
- KEY_ACTIONS =
Maps editing keys (left/right/home/end/backspace/delete) to the instance methods they dispatch via KeyboardHandler. Each symbol key (e.g., :left) maps to a method (e.g., :move_left) that adjusts cursor position or text content.
{ left: :move_left, right: :move_right, home: :move_home, end: :move_end, backspace: :delete_before_cursor, delete: :delete_at_cursor }.freeze
Constants included from KeyboardHandler
Instance Attribute Summary collapse
-
#cursor ⇒ Object
readonly
Returns the value of attribute cursor.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #handle_key(event) ⇒ Object
-
#initialize(value: "", placeholder: "", width: nil, cursor: nil) ⇒ TextInput
constructor
A new instance of TextInput.
- #render ⇒ Object
Methods inherited from View
Constructor Details
#initialize(value: "", placeholder: "", width: nil, cursor: nil) ⇒ TextInput
Returns a new instance of TextInput.
23 24 25 26 27 28 29 30 |
# File 'lib/charming/presentation/components/text_input.rb', line 23 def initialize(value: "", placeholder: "", width: nil, cursor: nil) super() @value = value.dup @placeholder = placeholder @width = width @cursor = cursor || @value.length clamp_position end |
Instance Attribute Details
#cursor ⇒ Object (readonly)
Returns the value of attribute cursor.
21 22 23 |
# File 'lib/charming/presentation/components/text_input.rb', line 21 def cursor @cursor end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
21 22 23 |
# File 'lib/charming/presentation/components/text_input.rb', line 21 def value @value end |
Instance Method Details
#handle_key(event) ⇒ Object
32 33 34 35 36 |
# File 'lib/charming/presentation/components/text_input.rb', line 32 def handle_key(event) return :handled if character_event?(event) && insert(event.char) super end |
#render ⇒ Object
38 39 40 41 |
# File 'lib/charming/presentation/components/text_input.rb', line 38 def render rendered = render_value @width ? style.width(@width).render(rendered) : rendered end |