Select
A compact trigger that picks one value from a list
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@nyte-ai/ui/select";For a searchable list, use Autocomplete. For a list of actions, use Menu.
Usage
- Pass
itemstoSelectsoSelectValueshows the chosen label instead of the raw value. onValueChangecan receivenull.- Name the trigger with
aria-label.
Anatomy
<Select>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="choice">Choice</SelectItem>
</SelectContent>
</Select>Examples
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@nyte-ai/ui/select";
import { useState } from "react";
type Theme = "system" | "light" | "dark";
const themes = [
{ value: "system", label: "System" },
{ value: "light", label: "Light" },
{ value: "dark", label: "Dark" },
] as const satisfies readonly { readonly value: Theme; readonly label: string }[];
function ThemeSelect() {
const [theme, setTheme] = useState<Theme>("system");
return (
<Select
items={themes}
value={theme}
onValueChange={(next) => {
if (next !== null) setTheme(next);
}}
>
<SelectTrigger aria-label="Theme">
<SelectValue />
</SelectTrigger>
<SelectContent>
{themes.map((option) => (
<SelectItem key={option.value} value={option.value} label={option.label}>
{option.label}
</SelectItem>
))}
</SelectContent>
</Select>
);
}<SelectTrigger aria-label="Default model" width="wide">
<SelectValue />
</SelectTrigger>Props
Styled parts take xstyle, className, and style; see
Theming. Each sets data-slot to its kebab-case name, such as
select-item. Select passes through Base UI.
The reference tables below come from Base UI, MIT, © Material-UI SAS.
Select
Groups all parts of the select. Doesn't render its own HTML element.
Root Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| name | string | - | Identifies the field when a form is submitted. |
| defaultValue | Value[] | Value | null | - | The uncontrolled value of the select when it's initially rendered. To render a controlled select, use the value prop instead. |
| value | Value[] | Value | null | - | The value of the select. Use when controlled. |
| onValueChange | ((value: Value[] | Value | null, eventDetails: Select.Root.ChangeEventDetails) => void) | - | Event handler called when the value of the select changes. |
| defaultOpen | boolean | false | Whether the select popup is initially open. To render a controlled select popup, use the open prop instead. |
| open | boolean | - | Whether the select popup is currently open. |
| onOpenChange | ((open: boolean, eventDetails: Select.Root.ChangeEventDetails) => void) | - | Event handler called when the select popup is opened or closed. |
| 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. |
| actionsRef | React.RefObject<Select.Root.Actions | 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. |
| form | string | - | Identifies the form that owns the hidden input. Useful when the select is rendered outside the form. |
| 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. |
| 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. |
| items | Record<string, React.ReactNode> | ({ label: React.ReactNode; value: any })[] | Group[] | - | 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. |
| 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. |
| onOpenChangeComplete | ((open: boolean) => void) | - | Event handler called after any animations complete when the select popup is opened or closed. |
| disabled | boolean | false | Whether the component should ignore user interaction. |
| 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. |
| inputRef | React.Ref<HTMLInputElement> | - | A ref to access the hidden input element. |
| id | string | - | The id of the Select. |
| children | React.ReactNode | - | - |
items Prop Example:
const items = {
sans: 'Sans-serif',
serif: 'Serif',
mono: 'Monospace',
cursive: 'Cursive',
};
<Select.Root items={items} />;autoComplete Prop References:
SelectTrigger
| Prop | Type | Default | Description |
|---|---|---|---|
width | "standard" | "wide" | "standard" | wide removes the 112px minimum and 180px maximum. |
A button that opens the select popup.
Renders a <button> element.
Trigger Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| 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>). |
| disabled | boolean | - | Whether the component should ignore user interaction. |
| children | React.ReactNode | - | - |
| className | string | ((state: Select.Trigger.State) => string | undefined) | - | CSS class applied to the element, or a function that returns a class based on the component's state. |
| style | React.CSSProperties | ((state: Select.Trigger.State) => React.CSSProperties | undefined) | - | Style applied to the element, or a function that returns a style object based on the component's state. |
| render | ReactElement | ((props: HTMLProps, state: Select.Trigger.State) => ReactElement) | - | 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. |
Trigger Data Attributes:
| Attribute | Type | Description |
|---|---|---|
| data-popup-open | - | Present when the corresponding select is open. |
| data-popup-side | 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start' | null | Indicates which side the corresponding popup is positioned relative to its anchor. |
| data-pressed | - | Present when the trigger is pressed. |
| data-disabled | - | Present when the select is disabled. |
| data-readonly | - | Present when the select is readonly. |
| data-required | - | Present when the select is required. |
| data-valid | - | Present when the select is in a valid state (when wrapped in Field.Root). |
| data-invalid | - | Present when the select is in an invalid state (when wrapped in Field.Root). |
| data-dirty | - | Present when the select's value has changed (when wrapped in Field.Root). |
| data-touched | - | Present when the select has been touched (when wrapped in Field.Root). |
| data-filled | - | Present when the select has a value (when wrapped in Field.Root). |
| data-focused | - | Present when the select trigger is focused (when wrapped in Field.Root). |
| data-placeholder | - | Present when the select doesn't have a value. |
SelectValue
A text label of the currently selected item.
Renders a <span> element.
Value Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| placeholder | React.ReactNode | - | The placeholder value to display when no value is selected.
This is overridden by children if specified, or by a null item's label in items. |
| children | React.ReactNode | ((value: any) => React.ReactNode) | - | Accepts a function that returns a ReactNode to format the selected value.
Treat the value as read-only: in multiple mode it may be a shared frozen array
when nothing is selected. |
| className | string | ((state: Select.Value.State) => string | undefined) | - | CSS class applied to the element, or a function that returns a class based on the component's state. |
| style | React.CSSProperties | ((state: Select.Value.State) => React.CSSProperties | undefined) | - | Style applied to the element, or a function that returns a style object based on the component's state. |
| render | ReactElement | ((props: HTMLProps, state: Select.Value.State) => ReactElement) | - | 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. |
children Prop Example:
<Select.Value>{(value: string | null) => (value ? labels[value] : 'No value')}</Select.Value>Value Data Attributes:
| Attribute | Type | Description |
|---|---|---|
| data-placeholder | - | Present when the select doesn't have a value. |
SelectContent
Renders the portal, positioner, popup, and list. The positioning props below go to the positioner. Everything else goes to the popup.
| Prop | Type | Default | Description |
|---|---|---|---|
side | "top" | "bottom" | "left" | "right" | "inline-start" | "inline-end" | "bottom" | |
align | "start" | "center" | "end" | "end" | |
sideOffset | number | OffsetFunction | 4 | Pixels. Ignored while the list is aligned to the trigger. |
alignOffset | number | OffsetFunction | ||
alignItemWithTrigger | boolean | true | Lays the list over the trigger with the chosen item on the trigger's value. Mouse input only. |
collisionAvoidance | CollisionAvoidance | { side: "flip", align: "shift", fallbackAxisSide: "none" } | |
tint | Tint | Scopes the popup to a hue. |
Positioner
Positions the select popup.
Renders a <div> element.
Positioner Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| 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. |
| disableAnchorTracking | boolean | false | Whether to disable the popup from tracking any layout shift of its positioning anchor. |
| align | Align | 'center' | How to align the popup relative to the specified side. |
| alignOffset | number | OffsetFunction | 0 | Additional offset along the alignment axis in pixels.
Also accepts a function that returns the offset 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. |
| side | Side | '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. |
| arrowPadding | number | 5 | Minimum distance to maintain between the arrow and the edges of the popup. Use it to prevent the arrow element from hanging out of the rounded corners of a popup. |
| anchor | Element | VirtualElement | React.RefObject<Element | null> | (() => Element | VirtualElement | null) | null | - | An element to position the popup against. By default, the popup will be positioned against the trigger. |
| collisionAvoidance | CollisionAvoidance | - | Determines how to handle collisions when positioning the popup. side controls overflow on the preferred placement axis (top/bottom or left/right): 'flip': keep the requested side when it fits; otherwise try the opposite side
(top and bottom, or left and right).'shift': never change side; keep the requested side and move the popup within
the clipping boundary so it stays visible.'none': do not correct side-axis overflow. align controls overflow on the alignment axis (start/center/end): 'flip': keep side, but swap start and end when the requested alignment overflows.'shift': keep side and requested alignment, then nudge the popup along the
alignment axis to fit.'none': do not correct alignment-axis overflow. fallbackAxisSide controls fallback behavior on the perpendicular axis when the
preferred axis cannot fit: 'start': allow perpendicular fallback and try the logical start side first
(top before bottom, or left before right in LTR).'end': allow perpendicular fallback and try the logical end side first
(bottom before top, or right before left in LTR).'none': do not fallback to the perpendicular axis. When side is 'shift', explicitly setting align only supports 'shift' or 'none'.
If align is omitted, it defaults to 'flip'. |
| collisionBoundary | Boundary | 'clipping-ancestors' | An element or a rectangle that delimits the area that the popup is confined to. |
| collisionPadding | Padding | 5 | Additional space to maintain from the edge of the collision boundary. |
| sticky | boolean | false | Whether to maintain the popup in the viewport after the anchor element was scrolled out of view. |
| positionMethod | 'absolute' | 'fixed' | 'absolute' | Determines which CSS position property to use. |
| className | string | ((state: Select.Positioner.State) => string | undefined) | - | CSS class applied to the element, or a function that returns a class based on the component's state. |
| style | React.CSSProperties | ((state: Select.Positioner.State) => React.CSSProperties | undefined) | - | Style applied to the element, or a function that returns a style object based on the component's state. |
| render | ReactElement | ((props: HTMLProps, state: Select.Positioner.State) => ReactElement) | - | 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. |
alignOffset Prop Example:
<Positioner
alignOffset={({ side, align, anchor, positioner }) => {
return side === 'top' || side === 'bottom' ? anchor.width : anchor.height;
}}
/>sideOffset Prop Example:
<Positioner
sideOffset={({ side, align, anchor, positioner }) => {
return side === 'top' || side === 'bottom' ? anchor.height : anchor.width;
}}
/>collisionAvoidance Prop Example:
<Positioner
collisionAvoidance={{
side: 'shift',
align: 'shift',
fallbackAxisSide: 'none',
}}
/>Positioner Data Attributes:
| Attribute | Type | Description |
|---|---|---|
| data-open | - | Present when the select popup is open. |
| data-closed | - | Present when the select popup is closed. |
| data-anchor-hidden | - | Present when the anchor is hidden. |
| data-align | 'start' | 'center' | 'end' | Indicates how the popup is aligned relative to specified side. |
| data-side | 'none' | 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start' | Indicates which side the popup is positioned relative to the trigger. |
Positioner CSS Variables:
| Variable | Type | Description |
|---|---|---|
--anchor-height | number | The anchor's height. |
--anchor-width | number | The anchor's width. |
--available-height | number | The available height between the trigger and the edge of the viewport. |
--available-width | number | The available width between the trigger and the edge of the viewport. |
--transform-origin | string | The coordinates that this element is anchored to. Used for animations and transitions. |
Popup
A container for the select list.
Renders a <div> element.
Popup Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| finalFocus | boolean | React.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. |
| children | React.ReactNode | - | - |
| className | string | ((state: Select.Popup.State) => string | undefined) | - | CSS class applied to the element, or a function that returns a class based on the component's state. |
| style | React.CSSProperties | ((state: Select.Popup.State) => React.CSSProperties | undefined) | - | Style applied to the element, or a function that returns a style object based on the component's state. |
| render | ReactElement | ((props: HTMLProps, state: Select.Popup.State) => ReactElement) | - | 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. |
Popup Data Attributes:
| Attribute | Type | Description |
|---|---|---|
| data-open | - | Present when the select is open. |
| data-closed | - | Present when the select is closed. |
| data-align | 'start' | 'center' | 'end' | Indicates how the popup is aligned relative to specified side. |
| data-side | 'none' | 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start' | Indicates which side the popup is positioned relative to the trigger. |
| data-starting-style | - | Present when the select begins animating in. |
| data-ending-style | - | Present when the select is animating out. |
List
A container for the select items.
Renders a <div> element.
List Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | ((state: Select.List.State) => string | undefined) | - | CSS class applied to the element, or a function that returns a class based on the component's state. |
| style | React.CSSProperties | ((state: Select.List.State) => React.CSSProperties | undefined) | - | Style applied to the element, or a function that returns a style object based on the component's state. |
| render | ReactElement | ((props: HTMLProps, state: Select.List.State) => ReactElement) | - | 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. |
SelectItem
An individual option in the select popup.
Renders a <div> element.
Item Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| 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. |
| value | any | null | A unique value that identifies this select item. |
| nativeButton | boolean | false | Whether the component renders a native <button> element when replacing it
via the render prop.
Set to true if the rendered element is a native button. |
| disabled | boolean | false | Whether the component should ignore user interaction. |
| children | React.ReactNode | - | - |
| className | string | ((state: Select.Item.State) => string | undefined) | - | CSS class applied to the element, or a function that returns a class based on the component's state. |
| style | React.CSSProperties | ((state: Select.Item.State) => React.CSSProperties | undefined) | - | Style applied to the element, or a function that returns a style object based on the component's state. |
| render | ReactElement | ((props: HTMLProps, state: Select.Item.State) => ReactElement) | - | 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. |
Item Data Attributes:
| Attribute | Type | Description |
|---|---|---|
| data-selected | - | Present when the select item is selected. |
| data-highlighted | - | Present when the select item is highlighted. |
| data-disabled | - | Present when the select item is disabled. |
Accessibility
- The trigger has
role="combobox", the listrole="listbox", and each optionrole="option"witharia-selected. - Arrow keys move through the options, Enter picks, and Escape closes. Typing matches option labels.
- Keyboard focus on the trigger shows the focus ring.