Select
Choose one value from a list that opens on demand, on Base UI: grouped options, disabled options, a placeholder and a portal you can place. For a few options that should all stay visible, use RadioGroup; for a plain native select, use Input.Select.
Import
From a Server Component, import the parts by name. In a 'use client' file, Select.Label, Select.Trigger, Select.Content, Select.Item, Select.Group, Select.GroupLabel and Select.Separator are the same parts.
import { Select, SelectContent, SelectItem, SelectLabel, SelectTrigger } from '@blocks/design-system'Pass items ({ value, label }[]) to Select so the trigger can show the selected label before the list has ever opened.
Source · select/named-parts.tsx
// A Server Component: named parts, uncontrolled, default portal.
import { Select, SelectContent, SelectItem, SelectLabel, SelectTrigger, Stack } from '@blocks/design-system'
const items = [
{ value: 'hourly', label: 'Every hour' },
{ value: 'daily', label: 'Once a day' },
{ value: 'weekly', label: 'Once a week' },
]
export default function NamedParts() {
return (
<Stack gap="xxs">
<Select items={items} defaultValue="daily">
<SelectLabel>Reading frequency</SelectLabel>
<SelectTrigger />
<SelectContent>
{items.map((item) => (
<SelectItem key={item.value} value={item.value}>
{item.label}
</SelectItem>
))}
</SelectContent>
</Select>
</Stack>
)
}Controlled, with a placeholder
Charting: nothing yet
Source · select/controlled.tsx
'use client'
import { Body, Select, Stack } from '@blocks/design-system'
import { useState } from 'react'
const items = [
{ value: 'depth', label: 'Snow depth' },
{ value: 'swe', label: 'Water equivalent' },
{ value: 'temp', label: 'Temperature' },
]
export default function Controlled() {
const [metric, setMetric] = useState<string | null>(null)
return (
<Stack gap="xs">
<Select items={items} value={metric} onValueChange={(value) => setMetric(value)}>
<Select.Label>Chart</Select.Label>
<Select.Trigger placeholder="Choose a reading" />
<Select.Content>
{items.map((item) => (
<Select.Item key={item.value} value={item.value}>
{item.label}
</Select.Item>
))}
</Select.Content>
</Select>
<Body margin="none">Charting: {metric ? items.find((item) => item.value === metric)?.label : 'nothing yet'}</Body>
</Stack>
)
}Groups, forms and themed portals
name makes the select submit with a native form. Group options with SelectGroup and SelectGroupLabel, and divide groups with SelectSeparator. Disabled options are announced and can’t be chosen.
The list renders in a portal at the end of document.body, so it escapes clipping containers. When the select sits in a subtree with its own theme (data-ds-theme), the body is outside that theme: pass container to SelectContent with an element inside the themed subtree.
Source · select/home-station.tsx
'use client'
import { Box, Button, Select, Stack } from '@blocks/design-system'
import { useState } from 'react'
const items = [
{ value: 'mount-hood', label: 'Mount Hood' },
{ value: 'stevens-pass', label: 'Stevens Pass' },
{ value: 'alta', label: 'Alta' },
{ value: 'big-sky', label: 'Big Sky' },
]
// The panel forces a dark theme. The list mounts inside the panel (not in
// document.body), so it inherits that theme.
export default function HomeStation() {
const [panel, setPanel] = useState<HTMLElement | null>(null)
return (
<Box as="section" ref={setPanel} data-ds-theme="dark" aria-label="Station settings" padding="lg" backgroundColor="bg" color="text">
<Stack as="form" action="/components/select" method="get" gap="sm" aria-label="Home station">
<Select name="station" items={items} defaultValue="mount-hood">
<Select.Label>Home station</Select.Label>
<Select.Trigger />
<Select.Content container={panel}>
<Select.Group>
<Select.GroupLabel>Pacific Northwest</Select.GroupLabel>
<Select.Item value="mount-hood">Mount Hood</Select.Item>
<Select.Item value="stevens-pass">Stevens Pass</Select.Item>
</Select.Group>
<Select.Separator />
<Select.Group>
<Select.GroupLabel>Rockies</Select.GroupLabel>
<Select.Item value="alta">Alta</Select.Item>
<Select.Item value="big-sky" disabled>
Big Sky (offline)
</Select.Item>
</Select.Group>
</Select.Content>
</Select>
<div>
<Button type="submit" variant="primary">
Save home station
</Button>
</div>
</Stack>
</Box>
)
}Keyboard
| Key | Action |
|---|---|
| ArrowDown / ArrowUp | Opens the list on the trigger; moves between options, skipping disabled ones. |
| Enter / Space | Selects the highlighted option and closes the list. |
| Escape | Closes the list without changing the value. Focus returns to the trigger. |
| Typing | Jumps to the option whose label starts with the typed text. |
Props
| Prop | Type | Default | Description |
|---|---|---|---|
actionsRef | RefObject<SelectRootActions | null> | — | A ref to imperative actions. - `unmount`: Manually unmounts the select. Call this after any externally controlled closing animation finishes. |
autoComplete | string | — | Provides a hint to the browser for autofill. @see https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/autocomplete |
defaultOpen | boolean | false | Whether the select popup is initially open. To render a controlled select popup, use the `open` prop instead. |
defaultValue | SelectValueType<Value, Multiple> | null | — | The uncontrolled value of the select when it's initially rendered. To render a controlled select, use the `value` prop instead. |
disabled | boolean | false | Whether the component should ignore user interaction. |
form | string | — | Identifies the form that owns the hidden input. Useful when the select is rendered outside the form. |
highlightItemOnHover | boolean | true | Whether moving the pointer over items should highlight them. Disabling this prop allows CSS `:hover` to be differentiated from the `:focus` (`data-highlighted`) state. |
id | string | — | The id of the Select. |
inputRef | Ref<HTMLInputElement> | — | A ref to access the hidden input element. |
isItemEqualToValue | ((itemValue: Value, value: Value) => boolean) | — | Custom comparison logic used to determine if a select item value matches the current selected value. Useful when item values are objects without matching referentially. Defaults to `Object.is` comparison. |
items | Record<string, ReactNode> | readonly { label: ReactNode; value: any; }[] | readonly Group<any>[] | — | Data structure of the items rendered in the select popup. When specified, `<Select.Value>` renders the label of the selected item instead of the raw value. @example ```tsx const items = { sans: 'Sans-serif', serif: 'Serif', mono: 'Monospace', cursive: 'Cursive', }; <Select.Root items={items} /> ``` |
itemToStringLabel | ((itemValue: Value) => string) | — | When the item values are objects (`<Select.Item value={object}>`), this function converts the object value to a string representation for display in the trigger. If the shape of the object is `{ value, label }`, the label will be used automatically without needing to specify this prop. |
itemToStringValue | ((itemValue: Value) => string) | — | When the item values are objects (`<Select.Item value={object}>`), this function converts the object value to a string representation for form submission. If the shape of the object is `{ value, label }`, the value will be used automatically without needing to specify this prop. |
modal | boolean | true | Determines if the select enters a modal state when open. - `true`: user interaction is limited to the select: document page scroll is locked and pointer interactions on outside elements are disabled. - `false`: user interaction with the rest of the document is allowed. On touch devices, a `true` modal blocks outside taps but leaves the page scrollable unless the popup spans nearly the full viewport width, matching native iOS behavior. |
multiple | boolean | false | Whether multiple items can be selected. |
name | string | — | Identifies the field when a form is submitted. |
onOpenChange | ((open: boolean, eventDetails: SelectRootChangeEventDetails) => void) | — | Event handler called when the select popup is opened or closed. |
onOpenChangeComplete | ((open: boolean) => void) | — | Event handler called after any animations complete when the select popup is opened or closed. |
onValueChange | ((value: SelectValueType<Value, Multiple> | (Multiple extends true ? never : null), eventDetails: SelectRootChangeEventDetails) => void) | — | Event handler called when the value of the select changes. |
open | boolean | — | Whether the select popup is currently open. |
readOnly | boolean | false | Whether the user should be unable to choose a different option from the select popup. |
required | boolean | false | Whether the user must choose a value before submitting a form. |
value | SelectValueType<Value, Multiple> | null | — | The value of the select. Use when controlled. |
| Prop | Type | Default | Description |
|---|---|---|---|
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, FieldRootState> | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.
| Prop | Type | Default | Description |
|---|---|---|---|
disabled | boolean | — | Whether the component should ignore user interaction. |
nativeButton | boolean | true | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`). |
placeholder | ReactNode | — | Shown when nothing is selected. |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectTriggerState> | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
size | "sm" | "md" | "lg" | — | Height from the `--ds-control-height-*` tokens. |
Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.
| Prop | Type | Default | Description |
|---|---|---|---|
align | "center" | "start" | "end" | 'center' | How to align the popup relative to the specified side. |
alignItemWithTrigger | boolean | true | Whether the positioner overlaps the trigger so the selected item's text is aligned with the trigger's value text. This only applies to mouse input and is automatically disabled if there is not enough space. |
container | HTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null> | null | — | Where the list mounts. Defaults to `document.body`; pass an element inside a `data-ds-theme` subtree so the list inherits its theme. |
finalFocus | boolean | RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | void | HTMLElement | null) | — | Determines the element to focus when the select popup is closed. - `false`: Do not move focus. - `true`: Move focus based on the default behavior (trigger or previously focused element). - `RefObject`: Move focus to the ref element. - `function`: Called with the interaction type (`mouse`, `touch`, `pen`, or `keyboard`). Return an element to focus, `true` to use the default behavior, or `false`/`undefined` to do nothing. |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectPopupState> | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
side | "top" | "bottom" | "left" | "right" | "inline-end" | "inline-start" | 'bottom' | Which side of the anchor element to align the popup against. May automatically change to avoid collisions. |
sideOffset | number | OffsetFunction | 0 | Distance between the anchor and the popup in pixels. Also accepts a function that returns the distance to read the dimensions of the anchor and positioner elements, along with its side and alignment. The function takes a `data` object parameter with the following properties: - `data.anchor`: the dimensions of the anchor element with properties `width` and `height`. - `data.positioner`: the dimensions of the positioner element with properties `width` and `height`. - `data.side`: which side of the anchor element the positioner is aligned against. - `data.align`: how the positioner is aligned relative to the specified side. @example ```jsx <Positioner sideOffset={({ side, align, anchor, positioner }) => { return side === 'top' || side === 'bottom' ? anchor.height : anchor.width; }} /> ``` |
Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.
| Prop | Type | Default | Description |
|---|---|---|---|
disabled | boolean | false | Whether the component should ignore user interaction. |
label | string | — | Specifies the text label to use when the item is matched during keyboard text navigation. Defaults to the item text content if not provided. |
nativeButton | boolean | true | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`). |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectItemState> | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
value | any | null | A unique value that identifies this select item. |
Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.
| Prop | Type | Default | Description |
|---|---|---|---|
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectGroupState> | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.
| Prop | Type | Default | Description |
|---|---|---|---|
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectGroupLabelState> | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | "horizontal" | "vertical" | 'horizontal' | The orientation of the separator. |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectSeparatorState> | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.
Accessibility
- Always render
SelectLabel(or label the trigger) so the combobox has a name. - Keep option labels short and distinct, since typing jumps by their first letters.
- A disabled option should say why when it isn’t obvious, as “(offline)” does.