Class: PhlexKit::ComboboxInputTrigger

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/phlex_kit/combobox/combobox_input_trigger.rb

Overview

Single-field trigger for PhlexKit::Combobox — the input doubles as the filter (autocomplete style): focusing or clicking opens the popover, typing filters, arrows/enter pick, and the chosen option's text becomes the field value. Ported from ruby_ui's RubyUI::ComboboxInputTrigger; upstream shipped the markup without controller support, so the behaviour (open-on-focus, keyboard nav from the field, selection reflection) is PhlexKit's completion of it. Keyboard actions live here because focus stays in this field — the popover's own bindings only fire for the button+search layout. See combobox.rb.

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(placeholder: "", disabled: false, invalid: false, list_id: nil, **attrs) ⇒ ComboboxInputTrigger

Returns a new instance of ComboboxInputTrigger.



12
13
14
15
16
17
18
# File 'app/components/phlex_kit/combobox/combobox_input_trigger.rb', line 12

def initialize(placeholder: "", disabled: false, invalid: false, list_id: nil, **attrs)
  @placeholder = placeholder
  @disabled = disabled
  @invalid = invalid
  @list_id = list_id
  @attrs = attrs
end

Instance Method Details

#view_templateObject



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
59
60
61
62
# File 'app/components/phlex_kit/combobox/combobox_input_trigger.rb', line 20

def view_template
  # The ARIA combobox role sits on the field itself (the interactive
  # element); the wrapper keeps aria-invalid only because the invalid
  # styling targets it. Pass `list_id:` matching the ComboboxList id to
  # wire aria-controls statically — otherwise the controller wires it.
  wrapper_aria = {}
  wrapper_aria[:invalid] = "true" if @invalid
  div(**mix({
    class: "pk-combobox-input-trigger",
    aria: wrapper_aria,
    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
    field_aria = { haspopup: "listbox", expanded: "false", autocomplete: "list", controls: @list_id }
    field_aria[:invalid] = "true" if @invalid
    input(
      type: :text,
      role: "combobox",
      aria: field_aria,
      placeholder: @placeholder,
      disabled: @disabled,
      autocomplete: "off",
      autocorrect: "off",
      spellcheck: "false",
      class: "pk-combobox-input-trigger-field",
      data: {
        phlex_kit__combobox_target: "inputTrigger",
        action: "keyup->phlex-kit--combobox#filterItems input->phlex-kit--combobox#filterItems"
      }
    )
    chevron_icon
  end
end