Class: PhlexKit::ComboboxBadgeTrigger
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- PhlexKit::ComboboxBadgeTrigger
- Defined in:
- app/components/phlex_kit/combobox/combobox_badge_trigger.rb
Overview
Multi-select trigger for PhlexKit::Combobox that shows each checked option as
a removable chip: the controller renders ComboboxBadge-style chips into the
badge container, backspace in the empty field removes the last one, and
clear_button: true adds a ComboboxClearButton. Ported from ruby_ui's
RubyUI::ComboboxBadgeTrigger; upstream shipped the markup without controller
support, so the badge rendering / backspace-removal / clear-all behaviour is
PhlexKit's completion of it. Keyboard actions live here because focus stays
in this field (see ComboboxInputTrigger). See combobox.rb.
Instance Method Summary collapse
-
#initialize(placeholder: "", clear_button: false, list_id: nil, **attrs) ⇒ ComboboxBadgeTrigger
constructor
A new instance of ComboboxBadgeTrigger.
- #view_template ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(placeholder: "", clear_button: false, list_id: nil, **attrs) ⇒ ComboboxBadgeTrigger
Returns a new instance of ComboboxBadgeTrigger.
11 12 13 14 15 16 |
# File 'app/components/phlex_kit/combobox/combobox_badge_trigger.rb', line 11 def initialize(placeholder: "", clear_button: false, list_id: nil, **attrs) @placeholder = placeholder @clear_button = @list_id = list_id @attrs = attrs end |
Instance Method Details
#view_template ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/components/phlex_kit/combobox/combobox_badge_trigger.rb', line 18 def view_template # The ARIA combobox role sits on the field itself (the interactive # element), not this wrapper. Pass `list_id:` matching the ComboboxList # id to wire aria-controls statically — otherwise the controller wires it. div(**mix({ class: "pk-combobox-badge-trigger", data: { placeholder: @placeholder, phlex_kit__combobox_target: "trigger", action: [ "click->phlex-kit--combobox#openPopover", "focusin->phlex-kit--combobox#openPopover", "keydown.down->phlex-kit--combobox#keyDownPressed", "keydown.up->phlex-kit--combobox#keyUpPressed", "keydown.enter->phlex-kit--combobox#keyEnterPressed", "keydown.esc->phlex-kit--combobox#closePopover:prevent" ].join(" ") } }, @attrs)) do div(class: "pk-combobox-badge-container pk-hidden", data: { phlex_kit__combobox_target: "badgeContainer" }) input( type: :text, role: "combobox", aria: { haspopup: "listbox", expanded: "false", autocomplete: "list", controls: @list_id }, placeholder: @placeholder, autocomplete: "off", autocorrect: "off", spellcheck: "false", class: "pk-combobox-badge-input", data: { phlex_kit__combobox_target: "badgeInput", action: [ "keyup->phlex-kit--combobox#filterItems", "input->phlex-kit--combobox#filterItems", "keydown.backspace->phlex-kit--combobox#handleBadgeInputBackspace" ].join(" ") } ) render ComboboxClearButton.new if @clear_button end end |