Listbox

A component for selecting a single or multiple items from a list.

Loading...

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 isItemDisabled to createListCollection.

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.

AttributeDefaultType
collection
ListCollection<T, never>

The collection of items

asChild
boolean

Use 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
string

The 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
boolean

Whether to disallow empty selection

disabled
boolean

Whether the listbox is disabled

disallowSelectAll
boolean

Whether to disallow selecting all items when `meta+a` is pressed

highlightedValue
string

The controlled key of the highlighted item

id
string

The 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.

loopFocusfalse
boolean

Whether to loop the keyboard navigation through the options

onHighlightChange
(details: HighlightChangeDetails<T>) => void

The callback fired when the highlighted item changes.

onSelect
(details: SelectionDetails) => void

Function called when an item is selected

onValueChange
(details: ValueChangeDetails<T>) => void

The 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) => void

Function to scroll to a specific index

selectionMode'single'
SelectionMode

How 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
boolean

Whether to select the item when it is highlighted

typeahead
boolean

Whether to enable typeahead on the listbox

value
string[]

The controlled keys of the selected items

AttributeDescription
[data-listbox-root]<uid>
[data-orientation]The orientation of the listbox
[data-disabled]Present when disabled

Content

Defines the <div> element.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[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.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDefaultType
asChild
boolean

Use 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.
autoHighlightfalse
boolean

Whether 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.

AttributeDescription
[data-listbox-input]<uid>
[data-disabled]Present when disabled

ItemGroupLabel

Defines the <div> element.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[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.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[data-listbox-item-indicator]<uid>
[data-state]"checked" | "unchecked"

Item

Defines the <div> element.

AttributeDefaultType
asChild
boolean

Use 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
boolean

Whether to highlight the item on hover

item
any

The 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.

AttributeDescription
[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.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[data-listbox-item-text]<uid>
[data-state]"checked" | "unchecked"
[data-disabled]Present when disabled
[data-highlighted]Present when highlighted

Label

Defines the <span> element.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[data-listbox-label]<uid>
[data-disabled]Present when disabled

List

Defines the <div> element.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[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 VariableDescription
--column-countThe column count value for the List

RootProvider

Defines the <div> element.

AttributeDefaultType
value
UseListboxReturn<T>

asChild
boolean

Use 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.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDefaultType
asChild
boolean

Use 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
string

Text 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.

AttributeDescription
[data-listbox-value-text]<uid>
[data-disabled]Present when disabled

Context

API

PropertyType
empty
boolean

Whether the select value is empty

highlightedValue
string | null

The value of the highlighted item

highlightedItem
V | null

The highlighted item

setHighlightedValue
(value: string | null) => void

Function to highlight a value, or clear the highlight with `null`

highlightFirst
VoidFunction

Function to highlight the first value

highlightLast
VoidFunction

Function to highlight the last value

highlightNext
VoidFunction

Function to highlight the next value

highlightPrevious
VoidFunction

Function to highlight the previous value

selectedItems
V[]

The selected items

hasSelectedItems
boolean

Whether there's a selected option

value
string[]

The selected item keys

valueAsString
string

The string representation of the selected items

selectValue
(value: string) => void

Function to select a value

selectAll
VoidFunction

Function 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[]) => void

Function to set the value of the select

clearValue
(value?: string) => void

Function 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) => ItemState

Returns the state of a select item

collection
ListCollection<V>

Function to toggle the select

disabled
boolean

Whether the select is disabled

getContentState
() => ContentState

Returns the state of the content

getListState
() => ListState

Returns the state of the list