Class: Shadcn::Combobox::Input::Component
- Inherits:
-
ApplicationViewComponent
- Object
- ViewComponent::Base
- ApplicationViewComponent
- Shadcn::Combobox::Input::Component
- Defined in:
- app/components/shadcn/combobox/input/component.rb
Overview
The field, inside an InputGroup with the chevron and — when asked for — the clear button in its trailing addon. Upstream composes exactly these three, and all three are ported here already.
Direct Known Subclasses
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.
-
#placeholder ⇒ Object
readonly
Returns the value of attribute placeholder.
-
#show_clear ⇒ Object
readonly
Returns the value of attribute show_clear.
-
#show_trigger ⇒ Object
readonly
Returns the value of attribute show_trigger.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from ApplicationViewComponent
Instance Method Summary collapse
- #call ⇒ Object
-
#element_attributes(**defaults) ⇒ Object
Base UI's combobox input is a
role="combobox"with the list underaria-controls, and the panel's open state onaria-expanded— the same contract Radix's select trigger has, which is why the controller can wire both the same way. -
#initialize(show_trigger: true, show_clear: false, disabled: false, placeholder: nil, value: nil, **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(show_trigger: true, show_clear: false, disabled: false, placeholder: nil, value: nil, **attributes) ⇒ Component
Returns a new instance of Component.
20 21 22 23 24 25 26 27 28 |
# File 'app/components/shadcn/combobox/input/component.rb', line 20 def initialize(show_trigger: true, show_clear: false, disabled: false, placeholder: nil, value: nil, **attributes) @show_trigger = show_trigger @show_clear = show_clear @disabled = disabled @placeholder = placeholder @value = value super(**attributes) end |
Instance Attribute Details
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
18 19 20 |
# File 'app/components/shadcn/combobox/input/component.rb', line 18 def disabled @disabled end |
#placeholder ⇒ Object (readonly)
Returns the value of attribute placeholder.
18 19 20 |
# File 'app/components/shadcn/combobox/input/component.rb', line 18 def placeholder @placeholder end |
#show_clear ⇒ Object (readonly)
Returns the value of attribute show_clear.
18 19 20 |
# File 'app/components/shadcn/combobox/input/component.rb', line 18 def show_clear @show_clear end |
#show_trigger ⇒ Object (readonly)
Returns the value of attribute show_trigger.
18 19 20 |
# File 'app/components/shadcn/combobox/input/component.rb', line 18 def show_trigger @show_trigger end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
18 19 20 |
# File 'app/components/shadcn/combobox/input/component.rb', line 18 def value @value end |
Instance Method Details
#call ⇒ Object
58 59 60 61 62 |
# File 'app/components/shadcn/combobox/input/component.rb', line 58 def call render(Shadcn::InputGroup::Component.new(class: "w-auto")) do safe_join([ field, addon ].compact) end end |
#element_attributes(**defaults) ⇒ Object
Base UI's combobox input is a role="combobox" with the list under
aria-controls, and the panel's open state on aria-expanded — the
same contract Radix's select trigger has, which is why the controller
can wire both the same way.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/components/shadcn/combobox/input/component.rb', line 34 def element_attributes(**defaults) super(**{ type: "text", value:, placeholder:, disabled: disabled.presence, role: "combobox", autocomplete: "off", autocapitalize: "none", autocorrect: "off", spellcheck: "false", "aria-autocomplete" => "list", "aria-haspopup" => "listbox", "aria-expanded" => "false", "data-shadcn--combobox-target" => "search", # `click`, not `focus`: taking an option puts the caret back in the # field, and on `focus` that reopened the panel the choice had just # closed. A pointer opens it by clicking, a keyboard by pressing # Down — which is what both do anyway. "data-action" => "input->shadcn--combobox#search click->shadcn--combobox#open " \ "keydown->shadcn--combobox#keydown" }.compact.merge(defaults)) end |