Class: Shadcn::Combobox::Trigger::Component

Inherits:
InputGroup::Button::Component show all
Defined in:
app/components/shadcn/combobox/trigger/component.rb

Overview

The chevron beside the field. Upstream renders it through InputGroupButton with asChild, so the button's own classes land on it — here that is a subclass, which is this gem's mapping for asChild.

Constant Summary collapse

ICON_CLASSES =
"pointer-events-none size-4 text-muted-foreground"

Constants inherited from InputGroup::Button::Component

InputGroup::Button::Component::SIZES

Constants inherited from ApplicationViewComponent

ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS

Instance Attribute Summary

Attributes inherited from InputGroup::Button::Component

#group_size

Attributes inherited from Button::Component

#size, #variant

Attributes inherited from ApplicationViewComponent

#attributes

Instance Method Summary collapse

Methods inherited from Button::Component

#style_variants, variant_classes

Methods inherited from ApplicationViewComponent

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

Constructor Details

#initialize(**attributes) ⇒ Component

Returns a new instance of Component.



18
19
20
# File 'app/components/shadcn/combobox/trigger/component.rb', line 18

def initialize(**attributes)
  super(variant: :ghost, size: :"icon-xs", **attributes)
end

Instance Method Details

#callObject



47
48
49
50
# File 'app/components/shadcn/combobox/trigger/component.rb', line 47

def call
  render_element(body: render(Icon::Component.new("chevron-down", class: ICON_CLASSES,
                                                  "data-slot": "combobox-trigger-icon")))
end

#css_classes(extra = nil) ⇒ Object



39
40
41
42
43
44
45
# File 'app/components/shadcn/combobox/trigger/component.rb', line 39

def css_classes(extra = nil)
  super([
    "[&_svg:not([class*='size-'])]:size-4",
    "group-has-data-[slot=combobox-clear]/input-group:hidden data-pressed:bg-transparent",
    extra
  ].compact.join(" "))
end

#element_attributes(**defaults) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/components/shadcn/combobox/trigger/component.rb', line 22

def element_attributes(**defaults)
  super(**{
    role: "combobox",
    # Named, where upstream's is not. Its rendered trigger is a
    # `role="combobox"` with a chevron in it and no text at all, and a
    # role that takes a name and has none is what axe calls a
    # `button-name` violation — the same correction Select, Checkbox and
    # Switch needed here.
    "aria-label" => shadcn_t("combobox.toggle"),
    "aria-haspopup" => "dialog",
    "aria-expanded" => "false",
    tabindex: "0",
    "data-shadcn--combobox-target" => "trigger",
    "data-action" => "click->shadcn--combobox#toggle"
  }.merge(defaults))
end