Class: Shadcn::Select::Trigger::Component
- Inherits:
-
ApplicationViewComponent
- Object
- ViewComponent::Base
- ApplicationViewComponent
- Shadcn::Select::Trigger::Component
- Defined in:
- app/components/shadcn/select/trigger/component.rb
Overview
SelectTrigger
Constant Summary collapse
- CHEVRON_CLASSES =
"size-4 opacity-50"
Constants inherited from ApplicationViewComponent
ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS
Instance Attribute Summary collapse
-
#disabled ⇒ Object
readonly
Returns the value of attribute disabled.
-
#placeholder ⇒ Object
readonly
Returns the value of attribute placeholder.
-
#searchable ⇒ Object
readonly
Returns the value of attribute searchable.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Attributes inherited from ApplicationViewComponent
Instance Method Summary collapse
- #call ⇒ Object
- #element_attributes(**defaults) ⇒ Object
-
#initialize(size: :default, placeholder: true, disabled: false, searchable: 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(size: :default, placeholder: true, disabled: false, searchable: false, **attributes) ⇒ Component
Returns a new instance of Component.
35 36 37 38 39 40 41 42 |
# File 'app/components/shadcn/select/trigger/component.rb', line 35 def initialize(size: :default, placeholder: true, disabled: false, searchable: false, **attributes) @size = size&.to_sym || :default @placeholder = placeholder @disabled = disabled @searchable = searchable super(**attributes) end |
Instance Attribute Details
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
33 34 35 |
# File 'app/components/shadcn/select/trigger/component.rb', line 33 def disabled @disabled end |
#placeholder ⇒ Object (readonly)
Returns the value of attribute placeholder.
33 34 35 |
# File 'app/components/shadcn/select/trigger/component.rb', line 33 def placeholder @placeholder end |
#searchable ⇒ Object (readonly)
Returns the value of attribute searchable.
33 34 35 |
# File 'app/components/shadcn/select/trigger/component.rb', line 33 def searchable @searchable end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
33 34 35 |
# File 'app/components/shadcn/select/trigger/component.rb', line 33 def size @size end |
Instance Method Details
#call ⇒ Object
66 67 68 |
# File 'app/components/shadcn/select/trigger/component.rb', line 66 def call render_element(body: safe_join([ value, content, chevron ].compact)) end |
#element_attributes(**defaults) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/components/shadcn/select/trigger/component.rb', line 44 def element_attributes(**defaults) super(**{ type: "button", # A searchable select's trigger is a plain button announcing a # listbox popup: the typing happens in the field inside the popover, # not here. shadcn's aria variant emits it that way, and it has the # side benefit that a role-less button can take its accessible name # from its own text, which `role="combobox"` cannot. role: ("combobox" unless searchable), disabled: (true if disabled), "aria-expanded" => "false", "aria-haspopup" => ("listbox" if searchable), "aria-autocomplete" => ("none" unless searchable), "data-size" => size, "data-state" => "closed", "data-placeholder" => (true if placeholder), "data-shadcn--select-target" => "trigger", "data-action" => "click->shadcn--select#toggle " \ "keydown->shadcn--select#triggerKeydown" }.merge(defaults)) end |