Get GliaKit

Forms

Select

An input-styled dropdown for picking one option from a short list, built on Radix Select.

Source
src/components/ui/select.tsx
Figma
Select · state (closed, open, error, disabled)

Usage

Included in the GliaKit boilerplate. Import it where you need it:

tsx
import {  Select,  SelectContent,  SelectItem,  SelectTrigger,  SelectValue,} from "@/components/ui/select";

When to use

  • Choosing one option from roughly 4 to 15 known values, such as a plan, role or sort order.
  • Compact settings and toolbars where a radio group would take too much room.
  • For long lists people would rather search, use Combobox.
  • For two or three options that should all be visible, use a radio group or a segmented control.
  • For actions rather than values, use a dropdown menu.

Examples

Controlled

Hold the value in state with value and onValueChange.

Error

Set aria-invalid on the trigger and pass error to Field.

Disabled

Disable the whole select, or single options with disabled on SelectItem.

In a toolbar

Give the trigger a fixed width to use it inline, here as a sort control next to a search field.

API reference

Select

Radix Select.Root. Holds the value; renders no markup of its own.

PropTypeDefaultDescription
valuestring-Controlled selected value.
defaultValuestring-Initial value when uncontrolled.
onValueChange(value: string) => void-Called when an option is picked.
disabledboolean-Disables the whole select.
namestring-Submits the value with a surrounding form.
requiredboolean-Marks the value as required for form validation.
open / onOpenChangeboolean / (open: boolean) => void-Control the open state yourself.

SelectTrigger

Input-styled button with a chevron. Extends Radix Select.Trigger props (id, aria-*, className).

PropTypeDefaultDescription
aria-invalidboolean-Shows the error style.
aria-labelstring-Accessible name when there is no linked Label.
classNamestring-Merged with the defaults. Full width by default; set a width such as w-44 for inline use.

SelectValue

Radix Select.Value. Shows the selected option's text inside the trigger.

PropTypeDefaultDescription
placeholderReact.ReactNode-Shown in muted text when nothing is selected.

SelectContent

The floating list, rendered in a portal. Extends Radix Select.Content props (side, align).

PropTypeDefaultDescription
position"popper" | "item-aligned""popper"popper opens below the trigger; item-aligned overlaps it with the selected item in place.
sideOffsetnumber6Gap between trigger and list in pixels.

SelectItem

One option. The selected option reads in violet with a check.

PropTypeDefaultDescription
valuestring-Required. The value passed to onValueChange.
disabledboolean-Shows the option dimmed and skips it during keyboard navigation.
textValuestring-Text used for type-ahead when children are not plain text.

Accessibility

  • Built on Radix Select: the trigger is a combobox and the list a listbox with options and aria-selected.
  • Enter, Space or Arrow Down opens the list; arrows move, Enter selects, Escape closes and returns focus to the trigger.
  • Type-ahead jumps to the first option starting with the typed letters.
  • Field's label is not linked automatically: give SelectTrigger an aria-label, or an id with a Label htmlFor.
  • Set aria-invalid on SelectTrigger for the error state.

Related