Class: Shadcn::Command::List::Component

Inherits:
ApplicationViewComponent show all
Defined in:
app/components/shadcn/command/list/component.rb

Overview

The scrolling list of options. role="listbox", and the input drives it from outside through aria-activedescendant — the virtual focus this gem already uses for the searchable select.

Constant Summary

Constants inherited from ApplicationViewComponent

ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS

Instance Attribute Summary collapse

Attributes inherited from ApplicationViewComponent

#attributes

Instance Method Summary collapse

Methods inherited from ApplicationViewComponent

#call, #css_classes, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name

Constructor Details

#initialize(ids: {}, **attributes) ⇒ Component

Returns a new instance of Component.



19
20
21
22
# File 'app/components/shadcn/command/list/component.rb', line 19

def initialize(ids: {}, **attributes)
  @ids = ids
  super(**attributes)
end

Instance Attribute Details

#idsObject (readonly)

Returns the value of attribute ids.



17
18
19
# File 'app/components/shadcn/command/list/component.rb', line 17

def ids
  @ids
end

Instance Method Details

#element_attributes(**defaults) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'app/components/shadcn/command/list/component.rb', line 24

def element_attributes(**defaults)
  super(**{
    "cmdk-list" => "",
    id: ids[:list],
    role: "listbox",
    "aria-labelledby" => ids[:label],
    "data-shadcn--command-target" => "list"
  }.compact.merge(defaults))
end