Overview
Select provides a dropdown menu for selecting a value from a list of options. It’s similar to a native<select> element but with enhanced customization, keyboard navigation, and accessibility features.
Features
- Full keyboard navigation
- Can be controlled or uncontrolled
- Supports custom placeholder
- Supports grouping of items
- Supports labels and separators
- Focus automatically managed
- Typeahead support
- Works inside forms
- Customizable positioning and collision detection
- Scrollable content area with scroll buttons
Installation
Anatomy
API Reference
Root
Contains all the select component parts.The controlled value of the select.
The value of the select when initially rendered (uncontrolled).
Event handler called when the value changes.
The controlled open state of the select.
The open state when initially rendered (uncontrolled).
Event handler called when the open state changes.
The reading direction. If omitted, inherits from the parent.
The name of the select. Submitted with its owning form as part of a name/value pair.
When true, prevents the user from interacting with the select.
When true, indicates that the user must select a value before the form can be submitted.
Trigger
The button that toggles the select.Change the default rendered element for the one passed as a child.
Value
The part that reflects the selected value. By default it will render the selected item’s text. Use theplaceholder prop for when there is no value.
The content that will be rendered when no value is selected.
Change the default rendered element for the one passed as a child.
Icon
A small icon often displayed next to the value as a visual affordance for the fact it can be opened.Change the default rendered element for the one passed as a child.
Portal
When used, portals the content part into the body.Specify a container element to portal the content into.
Content
The component that pops out when the select is open.Event handler called when focus moves back after closing.
Event handler called when the escape key is down.
Event handler called when a pointer event occurs outside the bounds of the component.
The positioning mode to use.
- item-aligned: Positions content aligned with the selected item
- popper: Positions content using a positioning engine
The preferred side of the trigger to render against when open (only available when position is set to
popper).The distance in pixels from the trigger (only available when position is set to
popper).The preferred alignment against the trigger (only available when position is set to
popper).An offset in pixels from the “start” or “end” alignment options (only available when position is set to
popper).When true, overrides the side and align preferences to prevent collisions (only available when position is set to
popper).The element(s) used as collision boundary (only available when position is set to
popper).The distance in pixels from the boundary edges (only available when position is set to
popper).The padding between the arrow and the edges of the content (only available when position is set to
popper).The sticky behavior on the align axis (only available when position is set to
popper).Whether to hide the content when the trigger becomes fully occluded (only available when position is set to
popper).Viewport
The scrolling viewport that contains all of the items.Change the default rendered element for the one passed as a child.
Item
The component that contains the select items.The value given as data when submitted with a name.
When true, prevents the user from interacting with the item.
Optional text used for typeahead purposes. By default the typeahead behavior will use the text content.
Change the default rendered element for the one passed as a child.
ItemText
The textual part of the item. It should only contain the text you want to announce to assistive technology when the item is selected.Change the default rendered element for the one passed as a child.
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.Change the default rendered element for the one passed as a child.
ScrollUpButton
An optional button used to indicate when the viewport can be scrolled up.Change the default rendered element for the one passed as a child.
ScrollDownButton
An optional button used to indicate when the viewport can be scrolled down.Change the default rendered element for the one passed as a child.
Group
Used to group multiple items. Use in conjunction with Label to ensure good accessibility via automatic labelling.Change the default rendered element for the one passed as a child.
Label
Used to render the label of a group. It won’t be focusable using arrow keys.Change the default rendered element for the one passed as a child.
Separator
Used to visually separate items in the select.Change the default rendered element for the one passed as a child.
Arrow
An optional arrow element to render alongside the content.The width of the arrow in pixels.
The height of the arrow in pixels.
Change the default rendered element for the one passed as a child.
Example
Accessibility
Adheres to the ListBox WAI-ARIA design pattern.
Keyboard Interactions
- Space - When focus is on the trigger, opens the select and focuses the selected item.
- Enter - When focus is on the trigger, opens the select and focuses the first item.
- ArrowDown - When focus is on the trigger, opens the select. When focus is on an item, moves focus to the next item.
- ArrowUp - When focus is on the trigger, opens the select. When focus is on an item, moves focus to the previous item.
- Esc - Closes the select and moves focus to the trigger.
- A-Z - When focus is on the trigger or an item, opens the select (if closed) and focuses the first item starting with that letter.