Native Solid 2 fork. Original documentation and designs © WorkOS; historical posts retain their original context.
Select
Displays a list of options for the user to pick from—triggered by a button.
Features
Can be controlled or uncontrolled.
Offers 2 positioning modes.
Supports items, labels, groups of items.
Focus is fully managed.
Full keyboard navigation.
Supports custom placeholder.
Typeahead support.
Supports Right to Left direction.
Anatomy
Import all parts and piece them together.
API Reference
Root
Contains all the parts of a select.
Trigger
The button that toggles the select. The Select.Content will position itself by aligning over the trigger.
Value
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.
Icon
A small icon often displayed next to the value as a visual affordance for the fact it can be open. By default renders ▼ but you can use your own icon via asChild or use children.
Portal
When used, portals the content part into the body.
Content
The component that pops out when the select is open.
Viewport
The scrolling viewport that contains all of the items.
Item
The component that contains the select items.
ItemText
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.
ItemIndicator
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.
ScrollUpButton
An optional button used as an affordance to show the viewport overflow as well as functionally enable scrolling upwards.
ScrollDownButton
An optional button used as an affordance to show the viewport overflow as well as functionally enable scrolling downwards.
Group
Used to group multiple items. use in conjunction with Select.Label to ensure good accessibility via automatic labelling.
Label
Used to render the label of a group. It won't be focusable using arrow keys.
Separator
Used to visually separate items in the select.
Arrow
An optional arrow element to render alongside the content. This can be used to help visually link the trigger with the Select.Content. Must be rendered inside Select.Content. Only available when position is set to popper.
Examples
Change the positioning mode
By default, Select will behave similarly to a native MacOS menu by positioning Select.Content relative to the active item. If you would prefer an alternative positioning approach similar to Popover or DropdownMenu then you can set position to popper and make use of additional alignment options such as side, sideOffset and more.
Constrain the content size
When using position="popper" on Select.Content, you may want to constrain the width of the content so that it matches the trigger width. You may also want to constrain its height to not exceed the viewport.
We expose several CSS custom properties such as --radix-select-trigger-width and --radix-select-content-available-height to support this. Use them to constrain the content dimensions.
With disabled items
You can add special styles to disabled items via the data-disabled attribute.
With a placeholder
You can use the placeholder prop on Value for when the select has no value. There's also a data-placeholder attribute on Trigger to help with styling.
With separators
Use the Separator part to add a separator between items.
With grouped items
Use the Group and Label parts to group items in a section.
With complex items
You can use custom content in your items.
Controlling the value displayed in the trigger
By default the trigger will automatically display the selected item ItemText's content. You can control what appears by chosing to put things inside/outside the ItemText part.
If you need more flexibility, you can control the component using value/onValueChange props and passing children to SelectValue. Remember to make sure what you put in there is accessible.
With custom scrollbar
The native scrollbar is hidden by default as we recommend using the ScrollUpButton and ScrollDownButton parts for the best UX. If you do not want to use these parts, compose your select with our Scroll Area primitive.
Decoupling the hidden input
By default, Select.Root renders a visually hidden select for form submission. To recompose, move, or exclude that element, you can build the select from its lower-level parts instead.
Important: These parts are unstable and prefixed with
unstable_, so their API may change in a future release.
Select.unstable_Providerprovides the select state and accepts the form-related and state props (name,value,defaultValue,onValueChange, etc.).Select.unstable_BubbleInputis the visually hiddenselectthatSelect.Rootrenders by default. Omit it when you don't need form submission.
Accessibility
Adheres to the ListBox WAI-ARIA design pattern.
See the W3C Select-Only Combobox example for more information.
Keyboard Interactions
Labelling
Use our Label component in order to offer a visual and accessible label for the select.
Custom APIs
Create your own API by abstracting the primitive parts into your own component.
Abstract down to Select and SelectItem
This example abstracts most of the parts.