codefast/ui

Command Palette

Search for a command to run...

Form

Select

Accessible dropdown selector. Supports groups, disabled options, and custom triggers.

Install

pnpm add @codefast/ui

Import path

@codefast/ui/select

Examples

Align Item With Trigger

Use the position prop on SelectContent to control alignment. When position='item-aligned' (default), the popup positions so the selected item appears over the trigger. When position='popper', the popup aligns to the trigger edge.

Toggle to align the item with the trigger.

Disabled

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

Groups

Use SelectGroup, SelectLabel, and SelectSeparator to organize items.

Invalid

<FieldLabel>Fruit</FieldLabel> <SelectTrigger aria-invalid> <SelectValue /> </SelectTrigger>

RTL

Right-to-left layout support for languages such as Arabic and Hebrew.

Translations are AI-generated for demonstration and may be imperfect.

Scrollable

A select with many items that scrolls.

Anatomy

How the parts compose. Copy this skeleton and fill in the slots.

import {
  Select, SelectTrigger, SelectValue,
  SelectContent, SelectGroup, SelectLabel, SelectItem,
} from "@codefast/ui/select";

<Select value={v} onValueChange={setV}>
  <SelectTrigger>
    <SelectValue placeholder="Choose…" />
  </SelectTrigger>
  <SelectContent>
    <SelectGroup>
      <SelectLabel>Group</SelectLabel>
      <SelectItem value="a">A</SelectItem>
    </SelectGroup>
  </SelectContent>
</Select>

API reference

Props for each part of the component. All native element props are also forwarded.

Select

Root. Owns the selected value.

PropTypeDefaultDescription
value / onValueChangestring / (value: string) => voidControlled selection and its handler.
defaultValuestringInitial value when uncontrolled.
disabledbooleanfalseDisables the whole control.

SelectGroup / SelectLabel

Wrap related options so screen readers announce the group, not just visual spacing.

PropTypeDefaultDescription
SelectLabel childrenReactNodeHeading text for the group (required inside SelectGroup for accessibility).

SelectItem

PropTypeDefaultDescription
valuestringThe value submitted when this item is chosen (required).
disabledbooleanfalseMakes a single option non-selectable.

Accessibility

Built to be keyboard-navigable and screen-reader friendly out of the box.

KeyFunction
SpaceOpens the menu when the trigger is focused.
Arrow+DownMoves to the next option.
Arrow+UpMoves to the previous option.
EnterSelects the highlighted option.
EscCloses without changing the value.
  • Implements the ARIA listbox pattern with type-ahead — start typing to jump to an option.
  • Use SelectLabel inside a SelectGroup so groups are announced, not just visually separated.
  • For native mobile behaviour with zero JS, prefer Native Select.

Guidelines

Conventions that keep usage consistent across an app.

Do

  • Always set a placeholder via SelectValue for empty state.
  • Group and label options once a list grows past ~7 items.

Don’t

  • Don’t use Select for boolean choices — use a Switch or Checkbox.
  • Don’t put interactive controls other than options inside the menu.