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

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

Constant Summary collapse

STIMULUS_CONTROLLER =
"combobox-dropdown"
STIMULUS_ACTION =
[
  "click->#{STIMULUS_CONTROLLER}#select",
  "keydown->#{STIMULUS_CONTROLLER}#onNavigate",
  "#{STIMULUS_CONTROLLER}:selected->#{Combobox::STIMULUS_CONTROLLER}#onSelect"
].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::Plumber::Base

Class Method Details

.default_optsObject



14
15
16
17
18
19
20
21
22
# File 'lib/stimulus_plumbers/components/combobox/dropdown.rb', line 14

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

Instance Method Details

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



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/stimulus_plumbers/components/combobox/dropdown.rb', line 24

def render(options: [], value: nil, label: nil, **_kwargs)
  listbox_attrs = merge_html_options(
    { classes: theme.resolve(:combobox_listbox).fetch(:classes, "") },
    { role: "listbox", data: { "#{STIMULUS_CONTROLLER}_target": "listbox" } }
  )
  listbox_attrs[:aria] = { label: label } if label

  template.(:ul, **listbox_attrs) do
    Options.new(template).render(options, value: value)
  end
end