Listbox
A component for selecting a single or multiple items from a list.
Anatomy
To set up the Listbox correctly, you'll need to understand its anatomy and how we name its parts.
Each part includes a
data-partattribute to help identify them in the DOM.
Examples
Basic
Here's a basic example of the Listbox component.
import { Listbox, createListCollection } from '@ark-ui/react/listbox'
import { CheckIcon } from 'lucide-react'
import styles from 'styles/listbox.module.css'
export const Basic = () => {
const collection = createListCollection({
items: [
{ label: 'United States', value: 'us' },
{ label: 'United Kingdom', value: 'uk' },
{ label: 'Canada', value: 'ca' },
{ label: 'Australia', value: 'au' },
{ label: 'Germany', value: 'de' },
{ label: 'France', value: 'fr' },
{ label: 'Japan', value: 'jp' },
],
})
return (
<Listbox.Root className={styles.Root} collection={collection}>
<Listbox.Label className={styles.Label}>Select Country</Listbox.Label>
<Listbox.Content className={styles.Content}>
{collection.items.map((item) => (
<Listbox.Item className={styles.Item} key={item.value} item={item}>
<Listbox.ItemText className={styles.ItemText}>{item.label}</Listbox.ItemText>
<Listbox.ItemIndicator className={styles.ItemIndicator}>
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
))}
</Listbox.Content>
</Listbox.Root>
)
}
import { Listbox, createListCollection } from '@ark-ui/solid/listbox'
import { CheckIcon } from 'lucide-solid'
import { Index } from 'solid-js'
import styles from 'styles/listbox.module.css'
export const Basic = () => {
const collection = createListCollection({
items: [
{ label: 'United States', value: 'us' },
{ label: 'United Kingdom', value: 'uk' },
{ label: 'Canada', value: 'ca' },
{ label: 'Australia', value: 'au' },
{ label: 'Germany', value: 'de' },
{ label: 'France', value: 'fr' },
{ label: 'Japan', value: 'jp' },
],
})
return (
<Listbox.Root class={styles.Root} collection={collection}>
<Listbox.Label class={styles.Label}>Select Country</Listbox.Label>
<Listbox.Content class={styles.Content}>
<Index each={collection.items}>
{(item) => (
<Listbox.Item class={styles.Item} item={item()}>
<Listbox.ItemText class={styles.ItemText}>{item().label}</Listbox.ItemText>
<Listbox.ItemIndicator class={styles.ItemIndicator}>
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
)}
</Index>
</Listbox.Content>
</Listbox.Root>
)
}
<script setup lang="ts">
import { Listbox, createListCollection } from '@ark-ui/vue/listbox'
import { CheckIcon } from 'lucide-vue-next'
import styles from 'styles/listbox.module.css'
const collection = createListCollection({
items: [
{ label: 'United States', value: 'us' },
{ label: 'United Kingdom', value: 'uk' },
{ label: 'Canada', value: 'ca' },
{ label: 'Australia', value: 'au' },
{ label: 'Germany', value: 'de' },
{ label: 'France', value: 'fr' },
{ label: 'Japan', value: 'jp' },
],
})
</script>
<template>
<Listbox.Root :class="styles.Root" :collection="collection">
<Listbox.Label :class="styles.Label">Select Country</Listbox.Label>
<Listbox.Content :class="styles.Content">
<Listbox.Item v-for="item in collection.items" :key="item.value" :class="styles.Item" :item="item">
<Listbox.ItemText :class="styles.ItemText">{{ item.label }}</Listbox.ItemText>
<Listbox.ItemIndicator :class="styles.ItemIndicator">
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
</Listbox.Content>
</Listbox.Root>
</template>
<script lang="ts">
import { Listbox, createListCollection } from '@ark-ui/svelte/listbox'
import CheckIcon from 'lucide-svelte/icons/check'
import styles from 'styles/listbox.module.css'
const collection = createListCollection({
items: [
{ label: 'United States', value: 'us' },
{ label: 'United Kingdom', value: 'uk' },
{ label: 'Canada', value: 'ca' },
{ label: 'Australia', value: 'au' },
{ label: 'Germany', value: 'de' },
{ label: 'France', value: 'fr' },
{ label: 'Japan', value: 'jp' },
],
})
</script>
<Listbox.Root class={styles.Root} {collection}>
<Listbox.Label class={styles.Label}>Select Country</Listbox.Label>
<Listbox.Content class={styles.Content}>
{#each collection.items as item (item.value)}
<Listbox.Item class={styles.Item} {item}>
<Listbox.ItemText class={styles.ItemText}>{item.label}</Listbox.ItemText>
<Listbox.ItemIndicator class={styles.ItemIndicator}>
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
{/each}
</Listbox.Content>
</Listbox.Root>
Controlled
The Listbox component can be controlled by using the value and onValueChange props. This allows you to manage the
selected value externally.
import { Listbox, createListCollection } from '@ark-ui/react/listbox'
import { CheckIcon } from 'lucide-react'
import { useState } from 'react'
import styles from 'styles/listbox.module.css'
export const Controlled = () => {
const collection = createListCollection({
items: [
{ label: 'Small', value: 'sm' },
{ label: 'Medium', value: 'md' },
{ label: 'Large', value: 'lg' },
{ label: 'Extra Large', value: 'xl' },
],
})
const [value, setValue] = useState(['md'])
return (
<Listbox.Root
className={styles.Root}
collection={collection}
value={value}
onValueChange={(e) => setValue(e.value)}
>
<Listbox.Label className={styles.Label}>Select Size</Listbox.Label>
<Listbox.Content className={styles.Content}>
{collection.items.map((item) => (
<Listbox.Item className={styles.Item} key={item.value} item={item}>
<Listbox.ItemText className={styles.ItemText}>{item.label}</Listbox.ItemText>
<Listbox.ItemIndicator className={styles.ItemIndicator}>
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
))}
</Listbox.Content>
</Listbox.Root>
)
}
import { Listbox, createListCollection } from '@ark-ui/solid/listbox'
import { CheckIcon } from 'lucide-solid'
import { Index, createSignal } from 'solid-js'
import styles from 'styles/listbox.module.css'
export const Controlled = () => {
const collection = createListCollection({
items: [
{ label: 'Small', value: 'sm' },
{ label: 'Medium', value: 'md' },
{ label: 'Large', value: 'lg' },
{ label: 'Extra Large', value: 'xl' },
],
})
const [value, setValue] = createSignal(['md'])
return (
<Listbox.Root class={styles.Root} collection={collection} value={value()} onValueChange={(e) => setValue(e.value)}>
<Listbox.Label class={styles.Label}>Select Size</Listbox.Label>
<Listbox.Content class={styles.Content}>
<Index each={collection.items}>
{(item) => (
<Listbox.Item class={styles.Item} item={item()}>
<Listbox.ItemText class={styles.ItemText}>{item().label}</Listbox.ItemText>
<Listbox.ItemIndicator class={styles.ItemIndicator}>
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
)}
</Index>
</Listbox.Content>
</Listbox.Root>
)
}
<script setup lang="ts">
import { Listbox, createListCollection } from '@ark-ui/vue/listbox'
import { CheckIcon } from 'lucide-vue-next'
import { ref } from 'vue'
import styles from 'styles/listbox.module.css'
const collection = createListCollection({
items: [
{ label: 'Small', value: 'sm' },
{ label: 'Medium', value: 'md' },
{ label: 'Large', value: 'lg' },
{ label: 'Extra Large', value: 'xl' },
],
})
const value = ref(['md'])
</script>
<template>
<Listbox.Root :class="styles.Root" :collection="collection" v-model="value">
<Listbox.Label :class="styles.Label">Select Size</Listbox.Label>
<Listbox.Content :class="styles.Content">
<Listbox.Item v-for="item in collection.items" :key="item.value" :class="styles.Item" :item="item">
<Listbox.ItemText :class="styles.ItemText">{{ item.label }}</Listbox.ItemText>
<Listbox.ItemIndicator :class="styles.ItemIndicator">
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
</Listbox.Content>
</Listbox.Root>
</template>
<script lang="ts">
import { Listbox, createListCollection } from '@ark-ui/svelte/listbox'
import CheckIcon from 'lucide-svelte/icons/check'
import styles from 'styles/listbox.module.css'
const collection = createListCollection({
items: [
{ label: 'Small', value: 'sm' },
{ label: 'Medium', value: 'md' },
{ label: 'Large', value: 'lg' },
{ label: 'Extra Large', value: 'xl' },
],
})
let value = $state(['md'])
</script>
<Listbox.Root
class={styles.Root}
{collection}
{value}
onValueChange={(e) => (value = e.value)}
>
<Listbox.Label class={styles.Label}>Select Size</Listbox.Label>
<Listbox.Content class={styles.Content}>
{#each collection.items as item (item.value)}
<Listbox.Item class={styles.Item} {item}>
<Listbox.ItemText class={styles.ItemText}>{item.label}</Listbox.ItemText>
<Listbox.ItemIndicator class={styles.ItemIndicator}>
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
{/each}
</Listbox.Content>
</Listbox.Root>
Disabled Item
Listbox items can be disabled using the disabled prop on the collection item.
Example not foundExample not foundExample not foundExample not foundYou can also use the
isItemDisabledwithin thecreateListCollectionto disable items based on a condition.
Multiple Selection
You can set the selectionMode property as multiple to allow the user to select multiple items at a time.
import { Listbox, createListCollection } from '@ark-ui/react/listbox'
import { CheckIcon } from 'lucide-react'
import styles from 'styles/listbox.module.css'
export const Multiple = () => {
const collection = createListCollection({
items: [
{ label: 'Monday', value: 'mon' },
{ label: 'Tuesday', value: 'tue' },
{ label: 'Wednesday', value: 'wed' },
{ label: 'Thursday', value: 'thu' },
{ label: 'Friday', value: 'fri' },
{ label: 'Saturday', value: 'sat' },
{ label: 'Sunday', value: 'sun' },
],
})
return (
<Listbox.Root className={styles.Root} collection={collection} selectionMode="multiple">
<Listbox.Label className={styles.Label}>Select Days</Listbox.Label>
<Listbox.Content className={styles.Content}>
{collection.items.map((item) => (
<Listbox.Item className={styles.Item} key={item.value} item={item}>
<Listbox.ItemText className={styles.ItemText}>{item.label}</Listbox.ItemText>
<Listbox.ItemIndicator className={styles.ItemIndicator}>
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
))}
</Listbox.Content>
</Listbox.Root>
)
}
import { Listbox, createListCollection } from '@ark-ui/solid/listbox'
import { CheckIcon } from 'lucide-solid'
import { Index } from 'solid-js'
import styles from 'styles/listbox.module.css'
export const Multiple = () => {
const collection = createListCollection({
items: [
{ label: 'Monday', value: 'mon' },
{ label: 'Tuesday', value: 'tue' },
{ label: 'Wednesday', value: 'wed' },
{ label: 'Thursday', value: 'thu' },
{ label: 'Friday', value: 'fri' },
{ label: 'Saturday', value: 'sat' },
{ label: 'Sunday', value: 'sun' },
],
})
return (
<Listbox.Root class={styles.Root} collection={collection} selectionMode="multiple">
<Listbox.Label class={styles.Label}>Select Days</Listbox.Label>
<Listbox.Content class={styles.Content}>
<Index each={collection.items}>
{(item) => (
<Listbox.Item class={styles.Item} item={item()}>
<Listbox.ItemText class={styles.ItemText}>{item().label}</Listbox.ItemText>
<Listbox.ItemIndicator class={styles.ItemIndicator}>
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
)}
</Index>
</Listbox.Content>
</Listbox.Root>
)
}
<script setup lang="ts">
import { Listbox, createListCollection } from '@ark-ui/vue/listbox'
import { CheckIcon } from 'lucide-vue-next'
import styles from 'styles/listbox.module.css'
const collection = createListCollection({
items: [
{ label: 'Monday', value: 'mon' },
{ label: 'Tuesday', value: 'tue' },
{ label: 'Wednesday', value: 'wed' },
{ label: 'Thursday', value: 'thu' },
{ label: 'Friday', value: 'fri' },
{ label: 'Saturday', value: 'sat' },
{ label: 'Sunday', value: 'sun' },
],
})
</script>
<template>
<Listbox.Root :class="styles.Root" :collection="collection" selectionMode="multiple">
<Listbox.Label :class="styles.Label">Select Days</Listbox.Label>
<Listbox.Content :class="styles.Content">
<Listbox.Item v-for="item in collection.items" :key="item.value" :class="styles.Item" :item="item">
<Listbox.ItemText :class="styles.ItemText">{{ item.label }}</Listbox.ItemText>
<Listbox.ItemIndicator :class="styles.ItemIndicator">
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
</Listbox.Content>
</Listbox.Root>
</template>
<script lang="ts">
import { Listbox, createListCollection } from '@ark-ui/svelte/listbox'
import CheckIcon from 'lucide-svelte/icons/check'
import styles from 'styles/listbox.module.css'
const collection = createListCollection({
items: [
{ label: 'Monday', value: 'mon' },
{ label: 'Tuesday', value: 'tue' },
{ label: 'Wednesday', value: 'wed' },
{ label: 'Thursday', value: 'thu' },
{ label: 'Friday', value: 'fri' },
{ label: 'Saturday', value: 'sat' },
{ label: 'Sunday', value: 'sun' },
],
})
</script>
<Listbox.Root class={styles.Root} {collection} selectionMode="multiple">
<Listbox.Label class={styles.Label}>Select Days</Listbox.Label>
<Listbox.Content class={styles.Content}>
{#each collection.items as item (item.value)}
<Listbox.Item class={styles.Item} {item}>
<Listbox.ItemText class={styles.ItemText}>{item.label}</Listbox.ItemText>
<Listbox.ItemIndicator class={styles.ItemIndicator}>
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
{/each}
</Listbox.Content>
</Listbox.Root>
Grouping
The Listbox component supports grouping items. You can use the groupBy function to group items based on a specific
property.
import { Listbox, createListCollection } from '@ark-ui/react/listbox'
import { CheckIcon } from 'lucide-react'
import styles from 'styles/listbox.module.css'
export const Group = () => {
const collection = createListCollection({
items: [
{ label: 'New York', value: 'nyc', region: 'North America' },
{ label: 'Los Angeles', value: 'lax', region: 'North America' },
{ label: 'Toronto', value: 'yyz', region: 'North America' },
{ label: 'London', value: 'lhr', region: 'Europe' },
{ label: 'Paris', value: 'cdg', region: 'Europe' },
{ label: 'Berlin', value: 'ber', region: 'Europe' },
{ label: 'Tokyo', value: 'nrt', region: 'Asia Pacific' },
{ label: 'Singapore', value: 'sin', region: 'Asia Pacific' },
{ label: 'Sydney', value: 'syd', region: 'Asia Pacific' },
],
groupBy: (item) => item.region,
})
return (
<Listbox.Root className={styles.Root} collection={collection}>
<Listbox.Label className={styles.Label}>Select Region</Listbox.Label>
<Listbox.Content className={styles.Content}>
{collection.group().map(([region, items]) => (
<Listbox.ItemGroup className={styles.ItemGroup} key={region}>
<Listbox.ItemGroupLabel className={styles.ItemGroupLabel}>{region}</Listbox.ItemGroupLabel>
{items.map((item) => (
<Listbox.Item className={styles.Item} key={item.value} item={item}>
<Listbox.ItemText className={styles.ItemText}>{item.label}</Listbox.ItemText>
<Listbox.ItemIndicator className={styles.ItemIndicator}>
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
))}
</Listbox.ItemGroup>
))}
</Listbox.Content>
</Listbox.Root>
)
}
import { Listbox, createListCollection } from '@ark-ui/solid/listbox'
import { CheckIcon } from 'lucide-solid'
import { For } from 'solid-js'
import styles from 'styles/listbox.module.css'
export const Group = () => {
const collection = createListCollection({
items: [
{ label: 'New York', value: 'nyc', region: 'North America' },
{ label: 'Los Angeles', value: 'lax', region: 'North America' },
{ label: 'Toronto', value: 'yyz', region: 'North America' },
{ label: 'London', value: 'lhr', region: 'Europe' },
{ label: 'Paris', value: 'cdg', region: 'Europe' },
{ label: 'Berlin', value: 'ber', region: 'Europe' },
{ label: 'Tokyo', value: 'nrt', region: 'Asia Pacific' },
{ label: 'Singapore', value: 'sin', region: 'Asia Pacific' },
{ label: 'Sydney', value: 'syd', region: 'Asia Pacific' },
],
groupBy: (item) => item.region,
})
return (
<Listbox.Root class={styles.Root} collection={collection}>
<Listbox.Label class={styles.Label}>Select Region</Listbox.Label>
<Listbox.Content class={styles.Content}>
<For each={collection.group()}>
{([region, items]) => (
<Listbox.ItemGroup class={styles.ItemGroup}>
<Listbox.ItemGroupLabel class={styles.ItemGroupLabel}>{region}</Listbox.ItemGroupLabel>
<For each={items}>
{(item) => (
<Listbox.Item class={styles.Item} item={item}>
<Listbox.ItemText class={styles.ItemText}>{item.label}</Listbox.ItemText>
<Listbox.ItemIndicator class={styles.ItemIndicator}>
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
)}
</For>
</Listbox.ItemGroup>
)}
</For>
</Listbox.Content>
</Listbox.Root>
)
}
<script setup lang="ts">
import { Listbox, createListCollection } from '@ark-ui/vue/listbox'
import { CheckIcon } from 'lucide-vue-next'
import styles from 'styles/listbox.module.css'
const collection = createListCollection({
items: [
{ label: 'New York', value: 'nyc', region: 'North America' },
{ label: 'Los Angeles', value: 'lax', region: 'North America' },
{ label: 'Toronto', value: 'yyz', region: 'North America' },
{ label: 'London', value: 'lhr', region: 'Europe' },
{ label: 'Paris', value: 'cdg', region: 'Europe' },
{ label: 'Berlin', value: 'ber', region: 'Europe' },
{ label: 'Tokyo', value: 'nrt', region: 'Asia Pacific' },
{ label: 'Singapore', value: 'sin', region: 'Asia Pacific' },
{ label: 'Sydney', value: 'syd', region: 'Asia Pacific' },
],
groupBy: (item) => item.region,
})
</script>
<template>
<Listbox.Root :class="styles.Root" :collection="collection">
<Listbox.Label :class="styles.Label">Select Region</Listbox.Label>
<Listbox.Content :class="styles.Content">
<Listbox.ItemGroup v-for="[region, items] in collection.group()" :key="region" :class="styles.ItemGroup">
<Listbox.ItemGroupLabel :class="styles.ItemGroupLabel">{{ region }}</Listbox.ItemGroupLabel>
<Listbox.Item v-for="item in items" :key="item.value" :class="styles.Item" :item="item">
<Listbox.ItemText :class="styles.ItemText">{{ item.label }}</Listbox.ItemText>
<Listbox.ItemIndicator :class="styles.ItemIndicator">
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
</Listbox.ItemGroup>
</Listbox.Content>
</Listbox.Root>
</template>
<script lang="ts">
import { Listbox, createListCollection } from '@ark-ui/svelte/listbox'
import CheckIcon from 'lucide-svelte/icons/check'
import styles from 'styles/listbox.module.css'
const collection = createListCollection({
items: [
{ label: 'New York', value: 'nyc', region: 'North America' },
{ label: 'Los Angeles', value: 'lax', region: 'North America' },
{ label: 'Toronto', value: 'yyz', region: 'North America' },
{ label: 'London', value: 'lhr', region: 'Europe' },
{ label: 'Paris', value: 'cdg', region: 'Europe' },
{ label: 'Berlin', value: 'ber', region: 'Europe' },
{ label: 'Tokyo', value: 'nrt', region: 'Asia Pacific' },
{ label: 'Singapore', value: 'sin', region: 'Asia Pacific' },
{ label: 'Sydney', value: 'syd', region: 'Asia Pacific' },
],
groupBy: (item) => item.region,
})
</script>
<Listbox.Root class={styles.Root} {collection}>
<Listbox.Label class={styles.Label}>Select Region</Listbox.Label>
<Listbox.Content class={styles.Content}>
{#each collection.group() as [region, items]}
<Listbox.ItemGroup class={styles.ItemGroup}>
<Listbox.ItemGroupLabel class={styles.ItemGroupLabel}>{region}</Listbox.ItemGroupLabel>
{#each items as item (item.value)}
<Listbox.Item class={styles.Item} {item}>
<Listbox.ItemText class={styles.ItemText}>{item.label}</Listbox.ItemText>
<Listbox.ItemIndicator class={styles.ItemIndicator}>
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
{/each}
</Listbox.ItemGroup>
{/each}
</Listbox.Content>
</Listbox.Root>
Guides
Type-Safety
The Listbox.RootComponent type enables you to create closed, strongly typed wrapper components that maintain full type
safety for collection items.
This is particularly useful when building reusable listbox components with custom props and consistent styling.
import { Listbox as ArkListbox, type CollectionItem } from '@ark-ui/react/listbox'
import { createListCollection } from '@ark-ui/react/collection'
interface ListboxProps<T extends CollectionItem> extends ArkListbox.RootProps<T> {}
const Listbox: ArkListbox.RootComponent = (props) => {
return <ArkListbox.Root {...props}>{/* ... */}</ArkListbox.Root>
}
Then, you can use the Listbox component as follows:
const App = () => {
const collection = createListCollection({
initialItems: [
{ label: 'React', value: 'react' },
{ label: 'Vue', value: 'vue' },
{ label: 'Svelte', value: 'svelte' },
],
})
return (
<Listbox
collection={collection}
onValueChange={(e) => {
// this will be strongly typed Array<{ label: string, value: string }>
console.log(e.items)
}}
>
{/* ... */}
</Listbox>
)
}
API Reference
Props
Root
| Prop | Default | Type |
|---|---|---|
collection | ListCollection<T>The collection of items | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. 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
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. |
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 |
| Data Attribute | Value |
|---|---|
[data-scope] | listbox |
[data-part] | root |
[data-orientation] | The orientation of the listbox |
[data-disabled] | Present when disabled |
Content
| Prop | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. For more details, read our Composition guide. |
| CSS Variable | Description |
|---|---|
--column-count | The column count value for the Content |
| Data Attribute | Value |
|---|---|
[data-scope] | listbox |
[data-part] | content |
[data-activedescendant] | The id the active descendant of the content |
[data-orientation] | The orientation of the content |
[data-layout] | |
[data-empty] | Present when the content is empty |
Empty
| Prop | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. For more details, read our Composition guide. |
Input
| Prop | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. For more details, read our Composition guide. | |
autoHighlight | false | booleanWhether to automatically highlight the item when typing |
| Data Attribute | Value |
|---|---|
[data-scope] | listbox |
[data-part] | input |
[data-disabled] | Present when disabled |
ItemGroupLabel
| Prop | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. For more details, read our Composition guide. |
ItemGroup
| Prop | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. For more details, read our Composition guide. |
| Data Attribute | Value |
|---|---|
[data-scope] | listbox |
[data-part] | item-group |
[data-disabled] | Present when disabled |
[data-orientation] | The orientation of the item |
[data-empty] | Present when the content is empty |
ItemIndicator
| Prop | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. For more details, read our Composition guide. |
| Data Attribute | Value |
|---|---|
[data-scope] | listbox |
[data-part] | item-indicator |
[data-state] | "checked" | "unchecked" |
Item
| Prop | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. For more details, read our Composition guide. | |
highlightOnHover | booleanWhether to highlight the item on hover | |
item | anyThe item to render |
| Data Attribute | Value |
|---|---|
[data-scope] | listbox |
[data-part] | item |
[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
| Prop | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. For more details, read our Composition guide. |
| Data Attribute | Value |
|---|---|
[data-scope] | listbox |
[data-part] | item-text |
[data-state] | "checked" | "unchecked" |
[data-disabled] | Present when disabled |
[data-highlighted] | Present when highlighted |
Label
| Prop | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. For more details, read our Composition guide. |
| Data Attribute | Value |
|---|---|
[data-scope] | listbox |
[data-part] | label |
[data-disabled] | Present when disabled |
RootProvider
| Prop | Default | Type |
|---|---|---|
value | UseListboxReturn<T> | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. For more details, read our Composition guide. |
ValueText
| Prop | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. For more details, read our Composition guide. | |
placeholder | stringText to display when no value is listboxed. |
| Data Attribute | Value |
|---|---|
[data-scope] | listbox |
[data-part] | value-text |
[data-disabled] | Present when disabled |
Context
These are the properties available when using Listbox.Context, useListboxContext hook or useListbox hook.
API
| Property | Type |
|---|---|
empty | booleanWhether the select value is empty |
highlightedValue | stringThe value of the highlighted item |
highlightedItem | VThe highlighted item |
highlightValue | (value: string) => voidFunction to highlight a value |
clearHighlightedValue | VoidFunctionFunction to clear the highlighted 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<any>) => ItemStateReturns the state of a select item |
collection | ListCollection<V>Function to toggle the select |
disabled | booleanWhether the select is disabled |