Class: StimulusPlumbers::Components::Combobox::Dropdown

Inherits:
Plumber::Base
  • Object
show all
Includes:
OptionGroup
Defined in:
lib/stimulus_plumbers/components/combobox/dropdown.rb

Overview

Renders a static listbox popover body with combobox-dropdown controller. Supports flat options, descriptions, and option groups.

Constant Summary collapse

"combobox-dropdown"
[
  "click->combobox-dropdown#select",
  "keydown->combobox-dropdown#navigate",
  "combobox-dropdown:selected->input-combobox#onSelected"
].join(" ").freeze

Constants included from Plumber::HtmlOptions

Plumber::HtmlOptions::STIMULUS_SPACEJOIN_KEYS

Instance Attribute Summary

Attributes inherited from Plumber::Base

#template

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Plumber::Base

#initialize, #theme

Methods included from Plumber::HtmlOptions

#merge_data_options, #merge_html_options, #merge_string_option, #normalize_part

Constructor Details

This class inherits a constructor from StimulusPlumbers::Components::Plumber::Base

Class Method Details

.default_optsObject



18
19
20
21
22
23
24
25
26
# File 'lib/stimulus_plumbers/components/combobox/dropdown.rb', line 18

def self.default_opts
  {
    popover: {
      tag:      :div,
      haspopup: "listbox",
      data:     { controller: DROPDOWN_CONTROLLER, action: DROPDOWN_ACTION }
    }
  }
end

Instance Method Details

#render(options: [], value: nil, label: nil, **_kwargs) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/stimulus_plumbers/components/combobox/dropdown.rb', line 28

def render(options: [], value: nil, label: nil, **_kwargs)
  listbox_attrs = { role: "listbox", data: { "#{DROPDOWN_CONTROLLER}_target": "listbox" } }
  listbox_attrs[:aria] = { label: label } if label

  listbox = template.(:ul, **listbox_attrs) do
    render_items(options, value: value)
  end

  template.safe_join([listbox])
end