Select
A dropdown component that presents a list of selectable options when triggered by a button.
Usage
You can use SelectPortal
to render the content in a different location in the DOM. See API Reference for details.
For more advanced usage, the additional components are available to customize the content and appearance of the Select
component. See API Reference for details.
API Reference
Select
Contains all the parts of a select. A styled wrapper around Radix Select.Root primitive with additional features.
Prop | Value | Default |
---|---|---|
label | ReactNode | / |
description | ReactNode | / |
tooltip | ReactNode | / |
helperText | ReactNode | / |
defaultOpen | boolean | / |
defaultValue | string | / |
dir | enum | / |
disabled | boolean | / |
name | string | / |
onOpenChange | function | / |
onValueChange | function | / |
open | boolean | / |
reqiured | boolean | / |
value | string | / |
SelectTrigger
The button that toggles the select. The SelectContent
component is rendered when the trigger is clicked.
Prop | Value | Default |
---|---|---|
asChild | boolean | false |
Data attribute | Value |
---|---|
[data-disabled] | Present when disabled |
[data-placeholder] | Present when has placeholder |
[data-state] | "open" | "closed" |
SelectValue
The part that reflects the selected value. By default the selected item’s text will be rendered. if you require more control, you can instead control the select and pass your own children
. It should not be styled to ensure correct positioning. An optional placeholder
prop is also available for when the select has no value.
Prop | Value | Default |
---|---|---|
asChild | boolean | false |
placeholder | ReactNode | / |
SelectIcon
A small icon often displayed next to the value as a visual affordance for the fact it can be open. By default renders a chevron icon pointed down or up depending on the open
state, but you can use your own icon via asChild
or use children
.
Prop | Value | Default |
---|---|---|
asChild | boolean | false |
SelectPortal
When used, portals the content part into the body
. By default it appends content to the body
, but you can specify a custom container
.
Prop | Value | Default |
---|---|---|
container | HTMLElement | document.body |
SelectContent
The component that pops out when the select is open. A styled wrapper around Radix Select.Content primitive with additional features.
Prop | Value | Default |
---|---|---|
asChild | boolean | false |
onCloseAutoFocus | function | / |
onEscapeKeyDown | function | / |
onPointerDownOutside | function | / |
position | enum | popper |
side | enum | "bottom" |
sideOffset | number | 8 |
align | enum | "start" |
alignOffset | number | 0 |
avoidCollisions | boolean | true |
collisionBoundary | Boundary | [] |
collisionPadding | number | Padding | 10 |
sticky | enum | "partial" |
hideWhenDetached | boolean | false |
showScrollButtons | boolean | false |
Data attribute | Value |
---|---|
[data-align] | "start" | "end" | "center" |
[data-side] | "left" | "right" | "bottom" | "top" |
[data-state] | "open" | "closed" |
CSS variables are available for this component. See Radix Select for more details.
SelectItem
The component that contains the select items.
By default SelectItemText
and SelectItemIndicator
are rendered inside the SelectItem
component. You can use your own components if you need to customize it via children
.
Prop | Value | Default |
---|---|---|
asChild | boolean | false |
disabled | boolean | false |
textValue | string | / |
value | string | / |
Data attribute | Value |
---|---|
[data-disabled] | Present when disabled |
[data-highlighted] | Present when highlighted |
[data-state] | "checked" | "unchecked" |
SelectItemText
The textual part of the item. It should only contain the text you want to see in the trigger when that item is selected. It should not be styled to ensure correct positioning.
Prop | Value | Default |
---|---|---|
asChild | boolean | false |
SelectItemIndicator
Renders when the item is selected. You can style this element directly, or you can use it as a wrapper to put an icon into, or both. By default it renders a checkmark icon.
Prop | Value | Default |
---|---|---|
asChild | boolean | false |
SelectGroup
Prop | Value | Default |
---|---|---|
asChild | boolean | false |
SelectLabel
Used to render the label of a group. It won’t be focusable using arrow keys.
Prop | Value | Default |
---|---|---|
asChild | boolean | false |
SelectSeparator
Used to visually separate items in the select.
Prop | Value | Default |
---|---|---|
asChild | boolean | false |
Accessibility
The Select
component supports all accessibility features of the Radix Select primitive.
Examples
The following example shows how to add icons to the SelectItem
and style them with Tailwind CSS. Icons are added using a custom DotIcon
component, which is placed inside each SelectItem
alongside the text. Tailwind classes like flex
and gap-1
are used to align and space the icons and text properly.
Each icon is styled with custom colors to represent different statuses.
Next example demonstrates how to structure your items, with groups separators, and labels. The SelectContent
component in this example uses a different content position
- item-aligned
.