Components

Select

Picks one value from a list. The list opens over the trigger with the current choice in place.

Usage

import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from 'nyctoui/select'

const items = { light: 'Light', dark: 'Dark' }

<Select items={items} defaultValue="light">
  <SelectTrigger aria-label="Theme">
    <SelectValue />
  </SelectTrigger>
  <SelectContent>
    <SelectItem value="light">Light</SelectItem>
    <SelectItem value="dark">Dark</SelectItem>
  </SelectContent>
</Select>

Pass items, a map of values to labels, so SelectValue can show the chosen label before the list has ever been opened.

Good for

  • Country or time zone on a profile form, with search.
  • A role picker when inviting a teammate: Admin, Member, Viewer.
  • Sort order in a list toolbar.
  • Choosing a currency or a language in settings.

Anatomy

<Select>
  <SelectTrigger>
    <SelectValue />
  </SelectTrigger>
  <SelectContent>
    <SelectGroup>
      <SelectLabel />
      <SelectItem />
    </SelectGroup>
    <SelectSeparator />
    <SelectItem />
  </SelectContent>
</Select>

Examples

With icons

Groups and placeholder

With no defaultValue, the trigger shows the placeholder of SelectValue.

Sizes

Below the trigger

Set alignItemWithTrigger={false} on SelectContent to drop the list below the trigger like a menu.

For a longer list, set searchable on SelectContent and put a SelectSearch, a SelectEmpty and the items in a SelectList inside it. Typing narrows the items while the arrow keys keep moving through them.

Controlled

Disabled

Best practices

Do
  • Give the select a visible label.
  • Write a placeholder that hints at the choice, like “Choose a time zone”, not “Select…”.
  • Group options with SelectGroup and SelectLabel when the list passes eight or so.
  • Turn on searchable for long lists such as countries.
Don’t
  • Use a select for actions. That’s a dropdown.
  • Use a select for two or three options. A segmented control shows them all at once.
  • Use a select for yes or no. That’s a switch or a checkbox.

API reference

Select

The ui-sdk Select root, with items as a label map. Renders no element.

PropTypeDefault
items
Labels for the values, so SelectValue shows one before the list first opens.
Record<string, string>—
value
The selected value, when controlled.
Value | null—
defaultValue
The value selected at first, when uncontrolled.
Value | null—
onValueChange
Called when the user picks a value.
(value, details) => void—
open / defaultOpen / onOpenChange
Control whether the list is open.
boolean · (open, details) => void—
disabled
Disables the trigger.
booleanfalse
name
Submits the value with a form under this name.
string—

SelectTrigger

The closed control. The chevron is built in.

PropTypeDefault
size
Control height; matches Button and Input.
'sm' | 'md' | 'lg''md'
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

SelectValue

The selected item’s label.

PropTypeDefault
placeholder
Shown while nothing is selected.
string—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

SelectContent

The popup with the list of options, in the top layer.

PropTypeDefault
searchable
Leaves the children as they are, for a SelectSearch above a SelectList.
booleanfalse
alignItemWithTrigger
Open over the trigger with the selected item in place.
booleantrue
side
Side of the trigger, when not aligned with it.
'top' | 'bottom' | 'left' | 'right' | 'start' | 'end''bottom'
align
Alignment along that side.
'start' | 'center' | 'end''start'
sideOffset
Gap between trigger and popup, in pixels.
number6
collisionPadding
Space kept from the viewport edges.
number8
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

SelectItem

One option, with a check when selected.

PropTypeDefault
value
The value this option selects.
Value—
icon
Icon shown before the label.
ReactNode—
disabled
Keeps the option from being picked.
booleanfalse
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

SelectGroup

Groups related options.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

SelectLabel

Heading for a SelectGroup.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

SelectSeparator

Hairline between options.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

SelectSearch

An <input> above the list of a searchable SelectContent. Give it an aria-label.

PropTypeDefault
placeholder
Hint shown while empty.
string'Search…'
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

SelectList

The scrolling list of items under a SelectSearch.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

SelectEmpty

Shown when the search matches nothing.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—