Class: Shadcn::Command::Item::Component
- Inherits:
-
ApplicationViewComponent
- Object
- ViewComponent::Base
- ApplicationViewComponent
- Shadcn::Command::Item::Component
- Defined in:
- app/components/shadcn/command/item/component.rb
Overview
One option. role="option", aria-selected for the virtual focus, and
data-selected for the classes — cmdk sets both, and shadcn's own
data-[selected=true]:bg-accent reads the second.
Constant Summary
Constants inherited from ApplicationViewComponent
ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS
Instance Attribute Summary collapse
-
#disabled ⇒ Object
readonly
Returns the value of attribute disabled.
-
#keywords ⇒ Object
readonly
Returns the value of attribute keywords.
-
#selected ⇒ Object
readonly
Returns the value of attribute selected.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from ApplicationViewComponent
Instance Method Summary collapse
- #element_attributes(**defaults) ⇒ Object
-
#initialize(value: nil, keywords: nil, disabled: false, selected: false, **attributes) ⇒ Component
constructor
value:is what is searched where it is given, and the item's own text otherwise — cmdk's rule.
Methods inherited from ApplicationViewComponent
#call, #css_classes, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name
Constructor Details
#initialize(value: nil, keywords: nil, disabled: false, selected: false, **attributes) ⇒ Component
value: is what is searched where it is given, and the item's own text
otherwise — cmdk's rule. keywords: are searched too and never shown,
which is how "Preferences" is found by typing "settings".
28 29 30 31 32 33 34 |
# File 'app/components/shadcn/command/item/component.rb', line 28 def initialize(value: nil, keywords: nil, disabled: false, selected: false, **attributes) @value = value @keywords = Array(keywords) @disabled = disabled @selected = selected super(**attributes) end |
Instance Attribute Details
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
23 24 25 |
# File 'app/components/shadcn/command/item/component.rb', line 23 def disabled @disabled end |
#keywords ⇒ Object (readonly)
Returns the value of attribute keywords.
23 24 25 |
# File 'app/components/shadcn/command/item/component.rb', line 23 def keywords @keywords end |
#selected ⇒ Object (readonly)
Returns the value of attribute selected.
23 24 25 |
# File 'app/components/shadcn/command/item/component.rb', line 23 def selected @selected end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
23 24 25 |
# File 'app/components/shadcn/command/item/component.rb', line 23 def value @value end |
Instance Method Details
#element_attributes(**defaults) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/components/shadcn/command/item/component.rb', line 36 def element_attributes(**defaults) super(**{ "cmdk-item" => "", id: item_id, role: "option", "aria-disabled" => (disabled.presence && "true"), "aria-selected" => selected.to_s, "data-disabled" => disabled.to_s, "data-selected" => selected.to_s, "data-value" => value, "data-keywords" => (keywords.join(" ").presence), "data-shadcn--command-target" => "item", "data-action" => "click->shadcn--command#choose pointermove->shadcn--command#hover" }.compact.merge(defaults)) end |