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, **attrs) ⇒ ComboboxBadgeTrigger
constructor
A new instance of ComboboxBadgeTrigger.
- #view_template ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(placeholder: "", clear_button: false, **attrs) ⇒ ComboboxBadgeTrigger
Returns a new instance of ComboboxBadgeTrigger.
11 12 13 14 15 |
# File 'app/components/phlex_kit/combobox/combobox_badge_trigger.rb', line 11 def initialize(placeholder: "", clear_button: false, **attrs) @placeholder = placeholder @clear_button = @attrs = attrs end |
Instance Method Details
#view_template ⇒ Object
17 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 |
# File 'app/components/phlex_kit/combobox/combobox_badge_trigger.rb', line 17 def view_template div(**mix({ class: "pk-combobox-badge-trigger", aria: { haspopup: "listbox", expanded: "false" }, 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, 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 |