Class: PhlexKit::SelectItem
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- PhlexKit::SelectItem
- Defined in:
- app/components/phlex_kit/select/select_item.rb
Overview
A selectable row in a PhlexKit::Select panel. Carries its value: in data-value; on
click/enter the controller copies it into the hidden SelectInput, updates the
SelectValue text, and flips aria-selected (which reveals the checkmark).
Pass selected: true to mark the initially-chosen item server-side — it's a
named kwarg (not an "aria-selected": attr) because mix would merge a
repeated attribute rather than override it.
See select.rb.
Instance Method Summary collapse
-
#initialize(value: nil, selected: false, **attrs) ⇒ SelectItem
constructor
A new instance of SelectItem.
- #view_template(&block) ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(value: nil, selected: false, **attrs) ⇒ SelectItem
Returns a new instance of SelectItem.
10 11 12 13 14 |
# File 'app/components/phlex_kit/select/select_item.rb', line 10 def initialize(value: nil, selected: false, **attrs) @value = value @selected = selected @attrs = attrs end |
Instance Method Details
#view_template(&block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/components/phlex_kit/select/select_item.rb', line 16 def view_template(&block) div(**mix({ role: "option", tabindex: "0", class: "pk-select-item", "aria-selected": (@selected ? "true" : "false"), data: { value: @value, controller: "phlex-kit--select-item", action: "click->phlex-kit--select#selectItem keydown.enter->phlex-kit--select#selectItem " \ "keydown.down->phlex-kit--select#handleKeyDown keydown.up->phlex-kit--select#handleKeyUp " \ "keydown.esc->phlex-kit--select#handleEsc", phlex_kit__select_target: "item" } }, @attrs)) do check_icon block&.call end end |