Demos

A select with a default value.

Usage

Use a select to pick one option from a list of five or more. For fewer options, a Radio Group shows them all at once. For actions rather than values, use a Dropdown Menu.

Import it from @workspace/ui/components/select.

Anatomy

  • Select — Holds the value. Pass items so the trigger can show the label.
  • SelectTrigger — The field. Shows a chevron.
  • SelectValue — The chosen label inside the trigger.
  • SelectContent — The list. By default it opens over the trigger, with the chosen item lined up on it.
  • SelectItem — One option. Shows a tick when chosen.
  • SelectGroup and SelectLabel — A labelled set of options. A label must sit inside a group.
  • SelectSeparator — A line between groups.

Notes

  • Without items, the trigger shows the raw value, such as female instead of Female.
  • For a placeholder, add an item with value: null to items and leave it out of the list.
  • Typing a letter jumps to the matching option.

Examples

Placeholder

Shows "Select a clinic" until the reader picks one.

Groups

Options under labels, with separators between groups.

Sizes

sm and default.

Disabled

A disabled select, and a select with one disabled option.

Props

These are the props you set most often. Unlisted props pass through to the underlying element.

Select

PropTypeDefaultDescription
items{ label, value }[]—Labels for each value, shown in the trigger.
defaultValuestring—Chosen on first render.
valuestring—The value when controlled.
onValueChange(value) => void—Called when the choice changes.
disabledbooleanfalseBlocks the whole field.
namestring—Field name for form submission.

SelectTrigger

PropTypeDefaultDescription
size"default" or "sm"default28 or 24 pixels tall.

SelectContent

PropTypeDefaultDescription
alignItemWithTriggerbooleantrueOpens over the trigger with the chosen item lined up. Set to false to open below.
side"top", "bottom", "left", or "right"bottomSide to open on when not aligned with the trigger.
align"start", "center", or "end"centerAlignment along that side.
sideOffsetnumber4Gap from the trigger, in pixels.

SelectItem

PropTypeDefaultDescription
valuestring—Value of the option.
disabledbooleanfalseBlocks the option.