Class: Charming::Presentation::Components::Form::Select
- Inherits:
-
Field
- Object
- View
- Charming::Presentation::Component
- Field
- Charming::Presentation::Components::Form::Select
- Defined in:
- lib/charming/presentation/components/form/select.rb
Instance Attribute Summary
Attributes inherited from Field
Instance Method Summary collapse
- #bind(state) ⇒ Object
- #handle_key(event) ⇒ Object
-
#initialize(name, options:, selected_index: 0, option_label: :to_s.to_proc, **field_options) ⇒ Select
constructor
A new instance of Select.
Methods inherited from Field
#focusable?, #render, #validate, #value
Methods inherited from View
#focused?, #layout_assigns, #render
Constructor Details
#initialize(name, options:, selected_index: 0, option_label: :to_s.to_proc, **field_options) ⇒ Select
Returns a new instance of Select.
8 9 10 11 12 13 |
# File 'lib/charming/presentation/components/form/select.rb', line 8 def initialize(name, options:, selected_index: 0, option_label: :to_s.to_proc, **) super(name, **) @options = @initial_selected_index = selected_index @option_label = option_label end |
Instance Method Details
#bind(state) ⇒ Object
15 16 17 18 |
# File 'lib/charming/presentation/components/form/select.rb', line 15 def bind(state) super ensure_selection end |
#handle_key(event) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/charming/presentation/components/form/select.rb', line 20 def handle_key(event) selection = list result = selection.handle_key(event) return nil unless result == :handled save_selection(selection.selected_index) :handled end |