Components
Select
Single-value picker with a button-styled trigger, grouped options and optional media per option.
import { Select } from "@openperf/deft";
<Select.Root defaultValue="member" items={roles}>
<Select.Trigger aria-label="Role" />
<Select.Content>
{roles.map((role) => (
<Select.Item key={role.value} value={role.value}>
{role.label}
</Select.Item>
))}
</Select.Content>
</Select.Root>;When to use
| Need | Component |
|---|---|
| One value from a handful of known options | Select |
| List long enough to need search, or several values | Combobox |
| List of commands | Menu |
| On/off choice | Switch |
Anatomy
<Select.Root>
<Select.Trigger /> {/* renders the value and the chevron itself */}
{/* portal, positioner, popup and list in one */}
<Select.Content>
<Select.Group>
<Select.GroupLabel />
<Select.Item /> {/* check mark when selected */}
</Select.Group>
<Select.Separator />
<Select.Item />
</Select.Content>
</Select.Root>Pass items ({ value, label }[]) to Select.Root: without it the trigger shows the raw value instead of the label. The remaining Base UI parts (Select.Value, Select.Icon, Select.Positioner, Select.Popup and the rest) are re-exported unstyled; Select.Trigger, Select.Content and Select.Item already render the ones they need.
Trigger and popup
The trigger takes size and variant of Button and is as wide as its content; a value or an item label that does not fit is cut with an ellipsis. The popup opens 4px from the trigger without overlapping it, is at least as wide as the trigger and scrolls when the list is taller than the space available.
Name the trigger with aria-label, or give it an id and point htmlFor of the Field.Label in a Field at it.
Media
media puts a decorative element before the label on Select.Item and on Select.Trigger. The trigger does not copy the media of the selected item: derive it from the current value. media and icon are hidden from assistive technology, so the label alone has to tell options apart.
Inline
size="inline" with variant="ghost" sets the trigger inside a sentence at the font size of the text around it.
API
Select.Root is Base UI Select.Root, unchanged: items, value, defaultValue, onValueChange, disabled and name.
Select.Trigger
Prop
Type
Select.Content
The remaining props go to Base UI Select.Popup.
Prop
Type
Select.Item
Prop
Type