Select
A common form component for choosing a predefined value in a dropdown menu.
API reference
Import the component and place its parts the following way:
import { Select } from '@base-ui-components/react/select';
<Select.Root>
<Select.Trigger>
<Select.Value />
<Select.Icon />
</Select.Trigger>
<Select.Portal>
<Select.Backdrop />
<Select.Positioner>
<Select.ScrollUpArrow />
<Select.Popup>
<Select.Arrow />
<Select.Item>
<Select.ItemText />
<Select.ItemIndicator />
</Select.Item>
<Select.Separator />
<Select.Group>
<Select.GroupLabel />
</Select.Group>
</Select.Popup>
<Select.ScrollDownArrow />
</Select.Positioner>
</Select.Portal>
</Select.Root>
Root
Groups all parts of the select. Doesn’t render its own HTML element.
Prop | Type | Default | |
---|---|---|---|
alignItemToTrigger | boolean | true | |
defaultOpen | boolean | false | |
defaultValue | any | null | |
disabled | boolean | false | |
name | string | undefined | |
onOpenChange | (open, event) => void | undefined | |
onValueChange | (value, event) => void | undefined | |
open | boolean | undefined | |
readOnly | boolean | false | |
required | boolean | false | |
value | any | undefined |
Trigger
A button that opens the select menu.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
className | string | (state) => string | undefined | |
disabled | boolean | false | |
label | string | undefined | |
render | | React.ReactElement | undefined |
Attribute | Description | |
---|---|---|
data-dirty | Present when the select's value has changed (when wrapped in Field.Root). | |
data-disabled | Present when the select is disabled. | |
data-invalid | Present when the select is in invalid state (when wrapped in Field.Root). | |
data-popup-open | Present when the corresponding select is open. | |
data-pressed | Present when the trigger is pressed. | |
data-readonly | Present when the select is readonly. | |
data-required | Present when the select is required. | |
data-touched | Present when the select has been thouched (when wrapped in Field.Root). | |
data-valid | Present when the select is in valid state (when wrapped in Field.Root).. |
Value
A text label of the currently selected item.
Renders a <span>
element.
Prop | Type | Default | |
---|---|---|---|
children | | React.ReactNode | undefined | |
className | string | (state) => string | undefined | |
placeholder | string | undefined | |
render | | React.ReactElement | undefined |
Icon
An icon that indicates that the trigger button opens a select menu.
Renders a <span>
element.
Prop | Type | Default | |
---|---|---|---|
className | string | (state) => string | undefined | |
render | | React.ReactElement | undefined |
Backdrop
An overlay displayed beneath the menu popup.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
className | string | (state) => string | undefined | |
keepMounted | boolean | false | |
render | | React.ReactElement | undefined |
Attribute | Description | |
---|---|---|
data-closed | Present when the select is closed. | |
data-ending-style | Present when the select is animating out. | |
data-open | Present when the select is open. | |
data-starting-style | Present when the select is animating in. |
Portal
A portal element that moves the popup to a different part of the DOM.
By default, the portal element is appended to <body>
.
Prop | Type | Default | |
---|---|---|---|
container | React.Ref | HTMLElement | null | undefined |
Positioner
Positions the select menu popup against the trigger.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
align | 'start' | 'center' | 'end' | 'start' | |
alignOffset | number | 0 | |
anchor | | React.Ref | undefined | |
arrowPadding | number | 5 | |
className | string | (state) => string | undefined | |
collisionBoundary | | 'clippingAncestors' | 'clipping-ancestors' | |
collisionPadding | number | Rect | 5 | |
positionMethod | 'absolute' | 'fixed' | 'absolute' | |
render | | React.ReactElement | undefined | |
side | | 'bottom' | 'bottom' | |
sideOffset | number | 0 | |
sticky | boolean | false | |
trackAnchor | boolean | true |
Attribute | Description | |
---|---|---|
data-anchor-hidden | Present when the anchor is hidden. | |
data-open | Present when the select popup is open. | |
data-side | Indicates which side the select is positioned relative to the trigger. | |
data-unchecked | Present when the select popup is closed. |
CSS Variable | Description | |
---|---|---|
--anchor-height | The anchor's height. | |
--anchor-width | The anchor's width. | |
--available-height | The available height between the trigger and the edge of the viewport. | |
--available-width | The available width between the trigger and the edge of the viewport. | |
--transform-origin | The coordinates that this element is anchored to. Used for animations and transitions. |
Popup
A container for the select items.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
className | string | (state) => string | undefined | |
render | | React.ReactElement | undefined |
Attribute | Description | |
---|---|---|
data-closed | Present when the select is closed. | |
data-ending-style | Present when the select is animating out. | |
data-open | Present when the select is open. | |
data-side | Indicates which side the select is positioned relative to the trigger. | |
data-starting-style | Present when the select is animating in. |
Arrow
Displays an element positioned against the select menu anchor.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
className | string | (state) => string | undefined | |
render | | React.ReactElement | undefined |
Attribute | Description | |
---|---|---|
data-anchor-hidden | Present when the anchor is hidden. | |
data-open | Present when the select popup is open. | |
data-side | Indicates which side the select is positioned relative to the trigger. | |
data-uncentered | Present when the tooltip arrow is uncentered. | |
data-unchecked | Present when the select popup is closed. |
Item
An individual option in the select menu.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
disabled | boolean | false | |
label | string | undefined | |
value | any | null |
ItemText
A text label of the select item.
Renders a <div>
element.
ItemIndicator
Indicates whether the select item is selected.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
className | string | (state) => string | undefined | |
keepMounted | boolean | false | |
render | | React.ReactElement | undefined |
Group
Groups related select items with the corresponding label.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
className | string | (state) => string | undefined | |
render | | React.ReactElement | undefined |
GroupLabel
An accessible label that is automatically associated with its parent group.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
className | string | (state) => string | undefined | |
render | | React.ReactElement | undefined |
ScrollUpArrow
An element that scrolls the select menu down when hovered.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
keepMounted | boolean | false |
Attribute | Description | |
---|---|---|
data-direction | Indicates the direction of the arrow. | |
data-side | Indicates which side the arrow is positioned relative to the select. | |
data-visible | Present when the arrow is visible. |
ScrollDownArrow
An element that scrolls the select menu down when hovered.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
keepMounted | boolean | false |
Attribute | Description | |
---|---|---|
data-direction | Indicates the direction of the arrow. | |
data-side | Indicates which side the arrow is positioned relative to the select. | |
data-visible | Present when the arrow is visible. |
Separator
A separator element accessible to screen readers.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
className | string | (state) => string | undefined | |
render | | React.ReactElement | undefined |