Select
A button that opens a list of options to choose from.
Installation
Shadwire follows shadcn/ui's open code model: the component's source is copied into your application and becomes yours. Install it with the CLI:
The select registry item installs these files:
-
app/components/ui_component.rb -
app/components/ui/select_component.rb -
app/components/ui/select/trigger_component.rb -
app/components/ui/select/value_component.rb -
app/components/ui/select/content_component.rb -
app/components/ui/select/item_component.rb -
app/components/ui/select/group_component.rb -
app/components/ui/select/label_component.rb -
app/components/ui/select/separator_component.rb -
app/components/ui/icon_component.rb -
app/helpers/ui/select_helper.rb -
app/helpers/ui/icon_helper.rb -
app/javascript/controllers/ui_select_controller.js -
vendor/shadwire/shadwire.css
This component uses Stimulus, so the application needs importmap-rails and stimulus-rails with automatic controller loading.
Haven't installed the CLI yet? gem install shadwire, then shadwire init.
Usage
The ui-select controller
follows the APG select-only combobox pattern: focus stays on the trigger
(role="combobox") and the active option
is announced through aria-activedescendant.
Selecting updates a hidden input and fires
change.
Or render the components directly:
Composition
Examples
Default
An APG combobox: focus stays on the trigger, arrows and typeahead navigate, and the active option uses aria-activedescendant.
Groups
Group options with a label and a separator; items can be disabled.
With form_with
The value is sent in a hidden input (name:). The native required attribute does not apply, so validate on the server.
API reference
Every part accepts class /
class_name and
**attrs.
| Component | Argument | Default | Description |
|---|---|---|---|
Select |
name |
nil |
The hidden input's name, for form submission. |
Select |
value |
nil |
The value selected at first. |
Select |
placeholder |
nil |
The text shown when nothing is selected. |
Select::Trigger |
size |
:default |
:default or :sm. |
Select::Item |
value: (required), disabled |
— | The option's value; disabled items are skipped during navigation. |