Class: StimulusPlumbers::Components::Combobox::Time::Drum

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

Constant Summary

Constants included from Plumber::HtmlOptions

Plumber::HtmlOptions::STIMULUS_SPACEJOIN_KEYS

Instance Attribute Summary

Attributes inherited from Plumber::Base

#template

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

Instance Method Details

#render(stimulus_controller:, target:, label:, items:, selected: nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/stimulus_plumbers/components/combobox/time/drum.rb', line 8

def render(stimulus_controller:, target:, label:, items:, selected: nil)
  template.(
    :ul,
    **merge_html_options(
      { classes: theme.resolve(:combobox_listbox).fetch(:classes, "") },
      {
        role:     "listbox",
        tabindex: "0",
        aria:     { label: label },
        data:     { "#{stimulus_controller}_target": target }
      },
      { data: { action: "click->#{stimulus_controller}#select keydown->#{stimulus_controller}#onNavigate" } }
    )
  ) do
    template.safe_join(
      items.map do |text, value|
        Options::Option.new(template).render(
          label:    text,
          value:    value,
          selected: value.to_s == selected.to_s
        )
      end
    )
  end
end