Listbox
A component for selecting a single or multiple items from a list.
Anatomy
<Listbox.Root>
<Listbox.Label />
<Listbox.Content>
<Listbox.ItemGroup>
<Listbox.ItemGroupLabel />
<Listbox.Item>
<Listbox.ItemText />
<Listbox.ItemIndicator />
</Listbox.Item>
</Listbox.ItemGroup>
</Listbox.Content>
<Listbox.ValueText />
</Listbox.Root>
Examples
Basic
Controlled
Use value and onValueChange to control the selected value.
Root Provider
Use RootProvider with the useListbox hook to access the state and methods from outside the component.
Disabled Item
Set disabled on a collection item to disable it.
To disable items by condition, pass
isItemDisabledtocreateListCollection.
Multiple
Set selectionMode="multiple" to let users select more than one item.
Grouping
Pass a groupBy function to group items by a property.
Extended Selection
Extended selection lets users select multiple items with Cmd (Mac) or Ctrl (Windows/Linux).
Horizontal
Set orientation="horizontal" to lay items out in a row.
Grid Layout
Use createGridCollection for a grid with keyboard navigation.
Filtering
Use the filter function from useListCollection to filter items.
Select All
Use useListboxContext to build a "Select All" control that selects or clears every item.
Value Text
Listbox.ValueText shows the selected values as a comma-separated string.
Virtualized
For large collections, use the Virtualizer to render only visible options. Render
Listbox.List as ListVirtualizer.Root and each Listbox.Item as ListVirtualizer.Item. Pass scrollToIndexFn so
keyboard navigation can reach unmounted options.
Guides
Type Safety
Use the Listbox.RootComponent type to build wrappers that keep collection items typed.
const Listbox: ArkListbox.RootComponent = (props) => {
return <ArkListbox.Root {...props}>{/* ... */}</ArkListbox.Root>
}
Callbacks like onValueChange then infer the item type:
const App = () => {
const collection = createListCollection({
initialItems: [
{ label: 'React', value: 'react' },
{ label: 'Vue', value: 'vue' },
],
})
return (
<Listbox
collection={collection}
onValueChange={(e) => {
// e.items is typed as Array<{ label: string, value: string }>
console.log(e.items)
}}
>
{/* ... */}
</Listbox>
)
}
API Reference
Props
Root
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
collection | ListCollection<T, never>The collection of items | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
defaultHighlightedValue | stringThe initial value of the highlighted item when opened. Use when you don't need to control the highlighted value of the listbox. | |
defaultValue | [] | string[]The initial default value of the listbox when rendered. Use when you don't need to control the value of the listbox. |
deselectable | booleanWhether to disallow empty selection | |
disabled | booleanWhether the listbox is disabled | |
disallowSelectAll | booleanWhether to disallow selecting all items when `meta+a` is pressed | |
highlightedValue | stringThe controlled key of the highlighted item | |
id | stringThe unique identifier of the machine. | |
ids | Partial<{
root: string
content: string
list: string
label: string
item: (id: string | number) => string
itemGroup: (id: string | number) => string
itemGroupLabel: (id: string | number) => string
}>The ids of the elements in the listbox. Useful for composition. | |
loopFocus | false | booleanWhether to loop the keyboard navigation through the options |
onHighlightChange | (details: HighlightChangeDetails<T>) => voidThe callback fired when the highlighted item changes. | |
onSelect | (details: SelectionDetails) => voidFunction called when an item is selected | |
onValueChange | (details: ValueChangeDetails<T>) => voidThe callback fired when the selected item changes. | |
orientation | 'vertical' | 'horizontal' | 'vertical'The orientation of the listbox. |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. | |
scrollToIndexFn | (details: ScrollToIndexDetails) => voidFunction to scroll to a specific index | |
selectionMode | 'single' | SelectionModeHow multiple selection should behave in the listbox. - `single`: The user can select a single item. - `multiple`: The user can select multiple items without using modifier keys. - `extended`: The user can select multiple items by using modifier keys. |
selectOnHighlight | booleanWhether to select the item when it is highlighted | |
typeahead | booleanWhether to enable typeahead on the listbox | |
value | string[]The controlled keys of the selected items |
| Attribute | Description |
|---|---|
[data-listbox-root] | <uid> |
[data-orientation] | The orientation of the listbox |
[data-disabled] | Present when disabled |
Content
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<ListboxContentState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-listbox-content] | <uid> |
[data-orientation] | The orientation of the content |
[data-layout] | |
[data-empty] | Present when the content is empty |
Empty
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Input
Defines the <input> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
autoHighlight | false | booleanWhether to automatically highlight the item when typing |
keyboardPriority | 'caret' | 'caret' | 'navigate'Determines how keyboard conflicts in the input are resolved. - "caret": keep native text-editing behavior - "navigate": forward supported keys to listbox navigation |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-listbox-input] | <uid> |
[data-disabled] | Present when disabled |
ItemGroupLabel
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
ItemGroup
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-listbox-item-group] | <uid> |
[data-disabled] | Present when disabled |
[data-orientation] | The orientation of the item |
[data-empty] | Present when the content is empty |
ItemIndicator
Defines the <span> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-listbox-item-indicator] | <uid> |
[data-state] | "checked" | "unchecked" |
Item
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
highlightOnHover | booleanWhether to highlight the item on hover | |
item | anyThe item to render | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<ListboxItemState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-listbox-item] | <uid> |
[data-value] | The value of the item |
[data-selected] | Present when selected |
[data-layout] | |
[data-state] | "checked" | "unchecked" |
[data-orientation] | The orientation of the item |
[data-highlighted] | Present when highlighted |
[data-disabled] | Present when disabled |
ItemText
Defines the <span> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-listbox-item-text] | <uid> |
[data-state] | "checked" | "unchecked" |
[data-disabled] | Present when disabled |
[data-highlighted] | Present when highlighted |
Label
Defines the <span> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-listbox-label] | <uid> |
[data-disabled] | Present when disabled |
List
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<ListboxListState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-listbox-list] | <uid> |
[data-activedescendant] | The id the active descendant of the list |
[data-orientation] | The orientation of the list |
[data-layout] | |
[data-empty] | Present when the content is empty |
| CSS Variable | Description |
|---|---|
--column-count | The column count value for the List |
RootProvider
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
value | UseListboxReturn<T> | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Status
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
ValueText
Defines the <span> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
placeholder | stringText to display when no value is listboxed. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-listbox-value-text] | <uid> |
[data-disabled] | Present when disabled |
Context
API
| Property | Type |
|---|---|
empty | booleanWhether the select value is empty |
highlightedValue | string | nullThe value of the highlighted item |
highlightedItem | V | nullThe highlighted item |
setHighlightedValue | (value: string | null) => voidFunction to highlight a value, or clear the highlight with `null` |
highlightFirst | VoidFunctionFunction to highlight the first value |
highlightLast | VoidFunctionFunction to highlight the last value |
highlightNext | VoidFunctionFunction to highlight the next value |
highlightPrevious | VoidFunctionFunction to highlight the previous value |
selectedItems | V[]The selected items |
hasSelectedItems | booleanWhether there's a selected option |
value | string[]The selected item keys |
valueAsString | stringThe string representation of the selected items |
selectValue | (value: string) => voidFunction to select a value |
selectAll | VoidFunctionFunction to select all values. **Note**: This should only be called when the selectionMode is `multiple` or `extended`. Otherwise, an exception will be thrown. |
setValue | (value: string[]) => voidFunction to set the value of the select |
clearValue | (value?: string) => voidFunction to clear the value of the select. If a value is provided, it will only clear that value, otherwise, it will clear all values. |
getItemState | (props: ItemProps) => ItemStateReturns the state of a select item |
collection | ListCollection<V>Function to toggle the select |
disabled | booleanWhether the select is disabled |
getContentState | () => ContentStateReturns the state of the content |
getListState | () => ListStateReturns the state of the list |