Class: Shadcn::Combobox::Item::Component
- Inherits:
-
ApplicationViewComponent
- Object
- ViewComponent::Base
- ApplicationViewComponent
- Shadcn::Combobox::Item::Component
- Defined in:
- app/components/shadcn/combobox/item/component.rb
Overview
One option, with the tick that marks the chosen one. data-highlighted
is the virtual focus — Base UI and Radix agree on that name, which is
why the select's arrangement carries over unchanged.
Constant Summary collapse
- INDICATOR_CLASSES =
"pointer-events-none absolute right-2 flex size-4 items-center justify-center"
Constants inherited from ApplicationViewComponent
ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS
Instance Attribute Summary collapse
-
#disabled ⇒ Object
readonly
Returns the value of attribute disabled.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#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
- #call ⇒ Object
- #element_attributes(**defaults) ⇒ Object
-
#initialize(value: nil, label: nil, selected: false, disabled: false, **attributes) ⇒ Component
constructor
A new instance of Component.
Methods inherited from ApplicationViewComponent
#css_classes, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name
Constructor Details
#initialize(value: nil, label: nil, selected: false, disabled: false, **attributes) ⇒ Component
Returns a new instance of Component.
26 27 28 29 30 31 32 |
# File 'app/components/shadcn/combobox/item/component.rb', line 26 def initialize(value: nil, label: nil, selected: false, disabled: false, **attributes) @value = value @label = label @selected = selected @disabled = disabled super(**attributes) end |
Instance Attribute Details
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
24 25 26 |
# File 'app/components/shadcn/combobox/item/component.rb', line 24 def disabled @disabled end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
24 25 26 |
# File 'app/components/shadcn/combobox/item/component.rb', line 24 def label @label end |
#selected ⇒ Object (readonly)
Returns the value of attribute selected.
24 25 26 |
# File 'app/components/shadcn/combobox/item/component.rb', line 24 def selected @selected end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
24 25 26 |
# File 'app/components/shadcn/combobox/item/component.rb', line 24 def value @value end |
Instance Method Details
#call ⇒ Object
47 48 49 |
# File 'app/components/shadcn/combobox/item/component.rb', line 47 def call render_element(body: safe_join([ content, indicator ])) end |
#element_attributes(**defaults) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/components/shadcn/combobox/item/component.rb', line 34 def element_attributes(**defaults) super(**{ id: item_id, role: "option", "aria-selected" => selected.to_s, "data-disabled" => (disabled.presence && ""), "data-value" => value, "data-label" => label, "data-shadcn--combobox-target" => "item", "data-action" => "click->shadcn--combobox#choose pointermove->shadcn--combobox#hover" }.compact.merge(defaults)) end |