Select

Displays a list of options for the user to pick from, triggered by a button.

Examples

Basic Select

A simple select with a few options.

Apple
Banana
Orange
<%= render "ui/select" do %>
  <%= render "ui/select/trigger", placeholder: "Select a fruit..." %>
  <%= render "ui/select/content" do %>
    <%= render "ui/select/item", value: "apple" do %>Apple<% end %>
    <%= render "ui/select/item", value: "banana" do %>Banana<% end %>
    <%= render "ui/select/item", value: "orange" do %>Orange<% end %>
  <% end %>
<% end %>

With Default Value

Select with a pre-selected value.

Apple
Banana
Orange
<%= render "ui/select", value: "banana" do %>
  <%= render "ui/select/trigger", placeholder: "Select a fruit..." %>
  <%= render "ui/select/content" do %>
    <%= render "ui/select/item", value: "apple" do %>Apple<% end %>
    <%= render "ui/select/item", value: "banana" do %>Banana<% end %>
    <%= render "ui/select/item", value: "orange" do %>Orange<% end %>
  <% end %>
<% end %>

With Disabled Items

Some items can be disabled to prevent selection.

Active
Pending
Archived
<%= render "ui/select" do %>
  <%= render "ui/select/trigger", placeholder: "Select a status..." %>
  <%= render "ui/select/content" do %>
    <%= render "ui/select/item", value: "active" do %>Active<% end %>
    <%= render "ui/select/item", value: "pending" do %>Pending<% end %>
    <%= render "ui/select/item", value: "archived", disabled: true do %>Archived<% end %>
  <% end %>
<% end %>

Scrollable

A select with a scrollable list of timezones.

North America
Eastern Standard Time (EST)
Central Standard Time (CST)
Mountain Standard Time (MST)
Pacific Standard Time (PST)
Alaska Standard Time (AKST)
Hawaii Standard Time (HST)
Europe & Africa
Greenwich Mean Time (GMT)
Central European Time (CET)
Eastern European Time (EET)
Western European Summer Time (WEST)
Central Africa Time (CAT)
East Africa Time (EAT)
Asia
Moscow Standard Time (MSK)
India Standard Time (IST)
China Standard Time (CST)
Japan Standard Time (JST)
Korea Standard Time (KST)
Indonesia Central Standard Time (WITA)
Australia & Pacific
Australian Western Standard Time (AWST)
Australian Central Standard Time (ACST)
Australian Eastern Standard Time (AEST)
New Zealand Standard Time (NZST)
Fiji Time (FJT)
South America
Argentina Time (ART)
Bolivia Time (BOT)
Brasilia Time (BRT)
Chile Standard Time (CLT)
<%= render "ui/select" do %>
  <%= render "ui/select/trigger", classes: "w-[280px]", placeholder: "Select a timezone" %>
  <%= render "ui/select/content" do %>
    <%= render "ui/select/group" do %>
      <%= render "ui/select/label" do %>North America<% end %>
      <%= render "ui/select/item", value: "est" do %>Eastern Standard Time (EST)<% end %>
      <%= render "ui/select/item", value: "cst" do %>Central Standard Time (CST)<% end %>
      <%= render "ui/select/item", value: "mst" do %>Mountain Standard Time (MST)<% end %>
      <%= render "ui/select/item", value: "pst" do %>Pacific Standard Time (PST)<% end %>
      <%= render "ui/select/item", value: "akst" do %>Alaska Standard Time (AKST)<% end %>
      <%= render "ui/select/item", value: "hst" do %>Hawaii Standard Time (HST)<% end %>
    <% end %>
    <%= render "ui/select/group" do %>
      <%= render "ui/select/label" do %>Europe & Africa<% end %>
      <%= render "ui/select/item", value: "gmt" do %>Greenwich Mean Time (GMT)<% end %>
      <%= render "ui/select/item", value: "cet" do %>Central European Time (CET)<% end %>
      <%= render "ui/select/item", value: "eet" do %>Eastern European Time (EET)<% end %>
      <%= render "ui/select/item", value: "west" do %>Western European Summer Time (WEST)<% end %>
      <%= render "ui/select/item", value: "cat" do %>Central Africa Time (CAT)<% end %>
      <%= render "ui/select/item", value: "eat" do %>East Africa Time (EAT)<% end %>
    <% end %>
    <%= render "ui/select/group" do %>
      <%= render "ui/select/label" do %>Asia<% end %>
      <%= render "ui/select/item", value: "msk" do %>Moscow Standard Time (MSK)<% end %>
      <%= render "ui/select/item", value: "ist" do %>India Standard Time (IST)<% end %>
      <%= render "ui/select/item", value: "cst_china" do %>China Standard Time (CST)<% end %>
      <%= render "ui/select/item", value: "jst" do %>Japan Standard Time (JST)<% end %>
      <%= render "ui/select/item", value: "kst" do %>Korea Standard Time (KST)<% end %>
      <%= render "ui/select/item", value: "ist_indonesia" do %>Indonesia Central Standard Time (WITA)<% end %>
    <% end %>
    <%= render "ui/select/group" do %>
      <%= render "ui/select/label" do %>Australia & Pacific<% end %>
      <%= render "ui/select/item", value: "awst" do %>Australian Western Standard Time (AWST)<% end %>
      <%= render "ui/select/item", value: "acst" do %>Australian Central Standard Time (ACST)<% end %>
      <%= render "ui/select/item", value: "aest" do %>Australian Eastern Standard Time (AEST)<% end %>
      <%= render "ui/select/item", value: "nzst" do %>New Zealand Standard Time (NZST)<% end %>
      <%= render "ui/select/item", value: "fjt" do %>Fiji Time (FJT)<% end %>
    <% end %>
    <%= render "ui/select/group" do %>
      <%= render "ui/select/label" do %>South America<% end %>
      <%= render "ui/select/item", value: "art" do %>Argentina Time (ART)<% end %>
      <%= render "ui/select/item", value: "bot" do %>Bolivia Time (BOT)<% end %>
      <%= render "ui/select/item", value: "brt" do %>Brasilia Time (BRT)<% end %>
      <%= render "ui/select/item", value: "clt" do %>Chile Standard Time (CLT)<% end %>
    <% end %>
  <% end %>
<% end %>

Features

  • Single selection from a list of options
  • Keyboard navigation with arrow keys
  • Type-ahead search functionality
  • Grouped options with labels
  • Disabled items support
  • Custom trigger with asChild pattern
  • Placeholder text when no selection
  • Form integration with hidden input

API Reference

Select

Shared behavior for Select component across ERB, ViewComponent, and Phlex implementations.

Parameters

NameTypeDefaultDescription
valueStringnilThe current value

Data Attributes

AttributeValuesDescription
data-stateopen, closedCurrent open/closed state
data-placeholdertruePresent when showing placeholder

CSS Variables

VariableDescription
--trigger-widthWidth of the trigger element

Content

Shared behavior for Select dropdown content across ERB, ViewComponent, and Phlex implementations.

Group

Shared behavior for Select options group across ERB, ViewComponent, and Phlex implementations.

Parameters

NameTypeDefaultDescription
as_childBooleanfalseWhen true, yields attributes to block instead of rendering wrapper

Item

Shared behavior for Individual select option across ERB, ViewComponent, and Phlex implementations.

Parameters

NameTypeDefaultDescription
as_childBooleanfalseWhen true, yields attributes to block instead of rendering wrapper
valueStringnilThe current value
disabledBooleanfalseWhether the element is disabled

Label

Shared behavior for Select group label across ERB, ViewComponent, and Phlex implementations.

Parameters

NameTypeDefaultDescription
as_childBooleanfalseWhen true, yields attributes to block instead of rendering wrapper

Scroll Down Button

Shared behavior for Select scroll down button across ERB, ViewComponent, and Phlex implementations.

Parameters

NameTypeDefaultDescription
as_childBooleanfalseWhen true, yields attributes to block instead of rendering wrapper

Scroll Up Button

Shared behavior for Select scroll up button across ERB, ViewComponent, and Phlex implementations.

Parameters

NameTypeDefaultDescription
as_childBooleanfalseWhen true, yields attributes to block instead of rendering wrapper

Trigger

Shared behavior for Select trigger button across ERB, ViewComponent, and Phlex implementations.

Parameters

NameTypeDefaultDescription
as_childBooleanfalseWhen true, yields attributes to block instead of rendering wrapper
placeholderStringSelect...Placeholder text when no value is selected

Accessibility

Implements the WAI-ARIA Listbox pattern with proper roles, states, and keyboard navigation.

ARIA Attributes

  • role="combobox" on the trigger
  • role="listbox" on the content container
  • role="option" on each item
  • aria-expanded on trigger
  • aria-selected on the selected item
  • aria-disabled on disabled items
  • aria-labelledby for label association

Keyboard Shortcuts

KeyDescription
SpaceOpens dropdown when trigger is focused
EnterOpens dropdown / selects highlighted item
ArrowDownOpens dropdown / moves to next item
ArrowUpMoves to previous item
HomeMoves to first item
EndMoves to last item
EscapeCloses dropdown
A-Z,a-zType-ahead to find matching item

JavaScript

Stimulus Controller

ui--select

Values

NameTypeDescription
openBooleanControls open state
valueStringCurrent selected value

Actions

togglecloseselectItem