Select
Displays a list of options for the user to pick from—triggered by a button.
Requires JS
This component requires the select
stimulus controller.
Anatomy
Select do |s|s.triggers.content dos.group dos.labels.items.itemends.items.itemendend
API Reference
Select
A dropdown selection component that supports both custom styled and native HTML select modes. Provides keyboard navigation, search functionality, and form integration.
Name | Type | Default |
---|---|---|
id: | string | nil |
name: | string | nil |
value: | string | nil |
placeholder: | string | nil |
native: | boolean | false |
include_blank: | boolean | false |
disabled: | boolean | false |
attributes | keyword arguments |
Select#trigger
Name | Type | |
---|---|---|
attributes | keyword arguments |
Select#content
Name | Type | Default |
---|---|---|
side: | symbol | :bottom |
Controls the side of the trigger to position the content. :top | :left | :bottom | :right | ||
align: | symbol | :center |
Controls the alignment the content relative to the trigger. :start | :center | :end | ||
attributes | keyword arguments |
Select#group
A container for grouping related select options with optional labels. Provides semantic structure and visual separation.
Name | Type | |
---|---|---|
attributes | keyword arguments |
Select#label
A non-selectable label for option groups. Used within group blocks to provide descriptive headings for grouped options.
Name | Type | |
---|---|---|
attributes | keyword arguments |
Select#item
An individual selectable option within the dropdown. Supports disabled states and automatic selection indicators.
Name | Type | Default |
---|---|---|
value: | string | nil |
The value submitted when this option is selected. Required for proper form submission and selection logic. | ||
disabled: | boolean | false |
When true, prevents this option from being selected and applies disabled styling. | ||
attributes | keyword arguments |
Select#items (Builder)
Builder method for generating select options from a collection.
Name | Type | Default |
---|---|---|
required collection | array | |
An array of objects or hashes for building select options. Each item becomes a selectable option. | ||
required value_method: | symbol | |
Method called on each collection item to get the option value for form submission. | ||
required text_method: | symbol | |
Method called on each collection item to get the display text for the option. | ||
disabled_items: | string or array | nil |
Values of select items to disable. Can be a single value or array of values matching the value_method results. | ||
attributes | keyword arguments |
Keyboard Interactions
Key | Description |
---|---|
Space | When focus is on trigger, opens the select and focuses the selected item. When focus is on an item, selects the focused item. |
Enter | When focus is on trigger, opens the select and focuses the selected item. When focus is on an item, selects the focused item. |
ArrowDown | When focus is on trigger, opens the select. When focus is on an item, moves focus to the next item. |
ArrowUp | When focus is on trigger, opens the select. When focus is on an item, moves focus to the previous item. |
Esc | Closes the select and moves focus to trigger. |
Examples
On This Page