Listbox
An always-visible list for selecting one or more options.
Usage guidelines
- Prefer Select for forms: Use Select instead of Listbox for selection in forms.
- Multi-select support: Set
multipleto allow selecting more than one item. The value is then an array. - Provide an accessible name: Prefer
<Listbox.Label>, or provide anaria-labelon<Listbox.List>when no visible label is rendered.
Anatomy
Import the component and assemble its parts:
Examples
Multiple selection
Add the multiple prop to let users select more than one item. The value is an array of the selected items.
Opt-in multiple selection
Use multiple="opt-in" when users opt in to selecting more than one item by holding a modifier key. On touch devices, which have no modifier keys, a tap adds or removes an item, the same as multiple.
Virtualized
Render large lists with a virtualization library such as @tanstack/react-virtual.
API reference
Root
Groups all parts of the listbox. Doesn’t render its own HTML element.
defaultValueUnion—
- Name
- Description
The uncontrolled value of the listbox when it’s initially rendered.
To render a controlled listbox, use the
valueprop instead.- Type
valueUnion—
- Name
- Description
The value of the listbox. Use when controlled.
- Type
onValueChangefunction—
- Name
- Description
Event handler called when the value of the listbox changes.
- Type
highlightItemOnHoverbooleantrue
- Description
Whether moving the pointer over an item highlights it. While focus is in the listbox, the item also receives focus. The pointer never takes focus from outside the listbox.
- Type
- Default
true
isItemEqualToValuefunction—
- Description
Custom comparison logic used to determine if a listbox item value matches the current selected value. Defaults to
Object.iscomparison.- Type
itemToStringLabelfunction—
- Description
When the item values are objects (
<Listbox.Item value={object}>), this function converts the object value to a string representation for typeahead. If the shape of the object is{ value, label }, the label will be used automatically without needing to specify this prop.- Type
itemsValue[]—
- Name
- Description
The items in the list, including those that aren’t rendered. Pass them when the list is virtualized, and use each item as its
Listbox.Itemvalue. Keyboard navigation, typeahead and selection can then reach items that aren’t rendered.- Type
multipleboolean | 'opt-in'false
- Name
- Description
Whether multiple items can be selected, and how selecting an item affects the current selection.
false: only one item can be selected.true: each item is toggled independently.'opt-in': selecting an item moves the current selection to it, and users hold a modifier key to select more than one item. On touch devices, where there are no modifier keys, it behaves liketrue.
- Type
- Default
false
onItemHighlightedfunction—
- Description
Callback fired when an item is highlighted or unhighlighted. Receives the highlighted item value (or
undefinedif no item is highlighted) and event details with areasonproperty describing why the highlight changed. Thereasoncan be:'keyboard': the highlight changed due to keyboard navigation or typeahead.'pointer': the highlight changed due to pointer hovering. The event may be aMouseEventrather than aPointerEvent.'none': the highlight changed for another reason, such as an item receiving or losing focus.
With
items, the highlighted item may not be rendered yet, so scroll it into view.- Type
disabledbooleanfalse
- Name
- Description
Whether the component should ignore user interaction.
- Type
- Default
false
orientation'vertical' | 'horizontal''vertical'
- Name
- Description
The orientation of the listbox for keyboard navigation.
- Type
- Default
'vertical'
childrenReact.ReactNode—
- Name
- Type
Listbox.Root.StateHide
Listbox.Root.ChangeEventReasonHide
Listbox.Root.ChangeEventDetailsHide
Listbox.Root.HighlightEventReasonHide
Listbox.Root.HighlightEventDetailsHide
Label
An accessible label that is automatically associated with the listbox.
Renders a <div> element.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
Listbox.Label.StateHide
List
A container for the listbox items.
Renders a <div> element.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-orientation
Indicates the orientation of the listbox.
data-disabled
Present when the listbox is disabled.
Attribute | Description | |
|---|---|---|
data-orientation | Indicates the orientation of the listbox. | |
data-disabled | Present when the listbox is disabled. | |
Listbox.List.StateHide
Item
An individual option in the listbox.
Renders a <div> element.
labelstring—
- Name
- Description
Overrides the text used for keyboard text navigation. Falls back to the rendered text when not provided.
- Type
valueanynull
- Name
- Description
A unique value that identifies this listbox item.
- Type
- Default
null
nativeButtonbooleanfalse
- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set totrueif the rendered element is a native button.- Type
- Default
false
disabledbooleanfalse
- Name
- Description
Whether the component should ignore user interaction.
- Type
- Default
false
childrenReact.ReactNode—
- Name
- Type
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-selected
Present when the listbox item is selected.
data-highlighted
Present when the listbox item is highlighted.
data-disabled
Present when the listbox item is disabled.
Attribute | Description | |
|---|---|---|
data-selected | Present when the listbox item is selected. | |
data-highlighted | Present when the listbox item is highlighted. | |
data-disabled | Present when the listbox item is disabled. | |
Listbox.Item.StateHide
ItemIndicator
Indicates whether the listbox item is selected.
Renders a <span> element.
childrenReact.ReactNode—
- Name
- Type
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
keepMountedboolean—
- Name
- Description
Whether to keep the HTML element in the DOM when the item is not selected.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
Listbox.ItemIndicator.PropsHide
Re-Export of ItemIndicator props as ListboxItemIndicatorProps
Listbox.ItemIndicator.StateHide
Group
Groups related listbox items with the corresponding label.
Renders a <div> element.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
Listbox.Group.StateHide
GroupLabel
An accessible label that is automatically associated with its parent group.
Renders a <div> element.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
Listbox.GroupLabel.PropsHide
Re-Export of GroupLabel props as ListboxGroupLabelProps