shadcn.io is an independent project built on shadcn/ui
On this page9 sections
A listbox keeps every option on the page, so people can compare them before they pick one or several. You build the options once as a collection and render a row for each, and the selection comes back as an array of their values.
Use a Select when the options should wait behind a button, and a Combobox when typing beats scanning.
Installation
Anatomy

Usage
<script setup lang="ts">
import { createListCollection } from "@/lib/collection"
import {
Listbox, ListboxContent, ListboxItem, ListboxItemIndicator,
ListboxItemText,
} from "@/components/ui/listbox"
const collection = createListCollection({
items: [
{ label: "Brazil", value: "br" },
{ label: "Mexico", value: "mx" },
{ label: "Ireland", value: "ie" },
],
});
</script>
<template>
<Listbox class="w-full max-w-64" :collection="collection" :defaultValue='["br"]'>
<ListboxContent aria-label="Country">
<ListboxItem v-for="item in collection.items" :item="item" :key="item.value">
<ListboxItemText>{{ item.label }}</ListboxItemText>
<ListboxItemIndicator />
</ListboxItem>
</ListboxContent>
</Listbox>
</template>Accessibility
ListboxContent renders the element with role="listbox", and each ListboxItem is an option that reports aria-selected, plus aria-disabled when it can't be picked. The list is one tab stop, and the arrow keys move real focus from row to row, so a screen reader follows it. Multiple and extended modes set aria-multiselectable. Naming the list is up to you: render ListboxLabel inside Listbox and the list takes its name from it, or put aria-label on ListboxContent when there is no visible heading. A label on Listbox itself reaches nobody, because its element has no role. UI SDK warns in development when the list has no name.
- Tab
- Moves focus into the list as a single stop: back to the item focused last, or else to the first selected item, or the first enabled one.
- Arrow Down
- Moves focus to the next item, skipping disabled ones. In a grid, moves to the same column in the next row. In extended mode, or with
selectOnHighlight, the item it reaches is selected too, unless Ctrl or Cmd is held. - Arrow Up
- Moves focus to the previous item, skipping disabled ones. In a grid, moves to the same column in the row above. In extended mode, or with
selectOnHighlight, the item it reaches is selected too, unless Ctrl or Cmd is held. - Arrow Right
- In a horizontal list or a grid, moves focus to the next item, or to the previous one in right-to-left text.
- Arrow Left
- In a horizontal list or a grid, moves focus to the previous item, or to the next one in right-to-left text.
- Home
- Moves focus to the first item.
- End
- Moves focus to the last item.
- Enter
- Selects the focused item. In multiple mode it toggles that item, and in single and extended modes it replaces the selection. With
deselectable, it clears the selected item of a single list. - Space
- Does what Enter does, except during a typeahead search, where it adds a space to the search.
- Shift+Arrow Down
- In multiple and extended modes, moves focus to the next item and extends the selection to it.
- Shift+Arrow Up
- In multiple and extended modes, moves focus to the previous item and extends the selection to it.
- Shift+Space
- In multiple and extended modes, selects the run from the last item chosen to the focused one.
- Ctrl+A
- In multiple and extended modes, selects every enabled item, and a second press clears them. Cmd + A on a Mac.
- EscEscape
- Leaves the selection alone, so a popover or dialog around the list can close.
- A-Z
- Moves focus to the next item whose label starts with the typed letters. In extended mode, or with
selectOnHighlight, that item is selected too.
Demos
Controlled
The parent holds the selection in state, starting on Medium out of four sizes, and the line under the list names the size that is picked. Hold the value yourself when a price, a preview or the next step depends on it. When nothing outside the list needs the value, setting defaultValue is enough.
Disabled
Brazil, Mexico and Ireland stay readable, but disabled on Listbox stops every click and key from changing the selection. Lock the whole list this way while an earlier answer is missing, or once the form has been sent. When only one option is off limits, disable that item and leave the rest working.
Disabled item
Of four plans, Enterprise is dimmed: its entry in the collection has disabled set to true, so clicks do nothing and the arrow keys skip over it. Use this for a sold-out tier, a plan the account can't buy or a step whose prerequisite isn't met, where people should still see the option exists.
Grid
Twenty emoji sit in five columns, built with createGridCollection and columnCount set to 5. Up and Down move a whole row in the same column, while Left and Right step through the items and carry on into the next row at the edge. Use a grid for emoji, color swatches or icons, where a single column would stretch short choices into a tall list.
Grouping
Brazil and Colombia sit under South America, Mexico and Canada under North America. The collection's groupBy puts each country in its region, and each group's label names the group for a screen reader without being an option itself. Group a long list when people already know its categories. A list as short as this one reads fine without headings.
Horizontal
Four albums sit in a row, each a square cover placeholder with the title and artist below and a check in the corner once chosen. ListboxLabel shows Favorite album above the row and names the list for a screen reader. With orientation set to horizontal, Left and Right move along the row, which scrolls when it overflows. Use it for covers, swatches or cards.
Image explorer
A narrow list of five places, with Mountain Landscape picked, drives a panel beside it that shows the chosen name and a one-line caption. The panel reads the selection from state, and on a phone the list moves above it. Use this layout when each option stands for something larger than its label, such as a photo or a document, and put the real preview in the panel.
Selection extended
With selectionMode set to extended, a plain click replaces the selection, Ctrl or Cmd with a click adds or removes one country, and Shift with a click selects the run between two. The note above the list tells people about the modifier. Choose it for file-manager lists where people expect a click to start over.
Selection multiple
Every click toggles its country and leaves the others alone, with selectionMode set to multiple. There is no modifier key to learn, which suits filters, tags and any set people treat like checkboxes. When a plain click should collapse the selection back to one item, extended mode is the better fit.
Selection none
New file, Edit file and Delete file, each with an icon, a short description and a shortcut label, under Actions and Danger zone headings. With selectionMode set to none no row stays checked, and the listbox reports no selection at all. The rows here only show the layout, so for commands people run by mouse and keyboard, use a Dropdown Menu.
Transfer list
Two lists in multiple mode, Available with Brazil and Ireland and Selected with Mexico, sit on either side of a pair of arrow buttons. A button stays disabled until its side has a selection, then moves those countries across. Use a transfer list when the task is deciding membership, such as who belongs to a team. For a short set, one multiple-selection list is less to build.
With description
Each country has a second line in small muted text, its region and language, inside the same row as the check mark. Add a line like this when the label alone leaves people guessing, and keep it to one short sentence so the row stays a row. A screen reader reads it as part of the option's name.
With filter
A search field above the countries narrows the list as someone types, ignoring case and accents. When nothing matches, ListboxEmpty puts a no-results line where the rows were. The narrowing comes from useListCollection with the contains matcher of useFilter. Add a filter once scanning takes longer than typing a few letters.
With icon
A flag sits before each country name and the check stays at the end of the row. The flag is plain content inside ListboxItem, so any icon or image goes the same way. Use one when the mark helps people find the row faster than the word does, and skip it when it only repeats the label.
With popover
A button shows the chosen country, or a placeholder before there is one, and opens a popover with a search field and the list. Picking a new country closes it through the select callback, and clicking the current one closes it too. Use this when the list shouldn't take up room until it's needed. If typing is how people choose, a Combobox ties the field and the list together.
FAQ
How do I control the selected Listbox items in Vue?
Bind an array ref with v-model on Listbox, which reads and writes the selected values. To handle each change yourself instead, pass :value and update it from @value-change, which receives the new array first and the change details, with the reason, second.
The value is an array of item values in every selection mode, so a single-select list holds one entry or none. The Controlled demo reads that array to decide what the line under the list says. When nothing outside the list needs the pick, set defaultValue and leave the state out.
How do I let people select more than one item in a Listbox?
Set selectionMode on Listbox to multiple or extended. In multiple every click toggles one item, as the Selection multiple demo shows. In extended a plain click replaces the selection and Ctrl or Cmd adds to it, as in Selection extended.
Both modes let Shift with a click or an arrow key select a run of items, and Ctrl+A, or Cmd+A on a Mac, select every enabled item, with a second press clearing them. The default is single, and none turns selection off.
How do I disable one option in a Listbox?
Set disabled to true on that item's object in the collection, and ListboxItem reads it from there, so the arrow keys skip the row and a click can't select it. A disabled prop on one ListboxItem does the same and wins over the collection.
A disabled row stays visible with data-disabled and aria-disabled on it, and the component dims it. The Disabled item demo does this for an Enterprise plan. To lock every row at once, set disabled on Listbox instead.
How do I add a search field to filter a Listbox?
Build the collection with useListCollection, pass it the contains matcher from useFilter, and call its filter function with the field's text on every change. The collection's items shrink to the matches, and ListboxEmpty shows its text when none are left, as in the With filter demo.
The field is a separate input, so its arrow keys don't move through the options: people press Tab to reach the list. When the field and the list should work as one control, use a Combobox.
Should I use a Listbox, a Select or a Combobox?
Use a listbox when the options should stay on screen: people compare them, pick several, or come back to change the pick often, as in a filter panel or a plan chooser. It costs the space of every row.
A Select folds the same choice into a button and fits a form with many fields. A Combobox adds a text field and suits long lists where people know what they're looking for and type it.
How do I submit the selected Listbox values with a form?
Give Listbox a name, and the selection goes out with the form, one entry per selected value under that name. Add required to block the submit while nothing is selected, and set form to the form's id when the list sits outside the form element.
With a form library, register the field yourself and pass the selection array to its setter from the change callback. Validation works on that array, so a required list checks that it isn't empty.
How do I make a long Listbox scroll?
Give ListboxContent a maximum height and an overflow class, such as max-h-64 and overflow-auto. The component ships the content with overflow-hidden, so rows past the height are cut off until you change it.
Once it scrolls, the arrow keys keep the highlighted row in view on their own. It also starts scrolled to the selected row, without moving focus there.
For thousands of rows, render only the visible ones with a virtualizer and pass scrollToIndexFn to Listbox, which the listbox calls to bring a highlighted row into view. Each row's aria-posinset and aria-setsize come from the collection, so a screen reader hears the full count even when only some rows are rendered.
How do I style the selected and highlighted Listbox items?
Target the data attributes the items carry. A selected item has data-selected, the item with focus has data-highlighted, and a disabled one has data-disabled. A click focuses the row it lands on, so the highlight shows for mouse users too, until focus leaves the list.
The default look lives in listboxItemVariants in components/ui/listbox, which is your file once installed. Set variant to destructive for a red row, and put your own icon inside ListboxItemIndicator to replace the check.
API Reference
Listbox
value?string[]
The selected values. Pass it to control the listbox. Two-way with v-model.
defaultValue?string[]
The values selected at first, when uncontrolled.
- Default
[]
collection?ListCollection<T>
The items, with how to read each one's value, text and disabled state.
- Type
ListCollection<T>
defaultHighlightedValue?string | null
The item highlighted at first, when uncontrolled: it takes the tab stop.
- Type
string | null
deselectable?boolean
Whether pressing the selected item of a single listbox unselects it.
disabled?boolean
Whether the listbox can't be focused or changed.
- Default
false
form?string
The id of a form to belong to, outside that form.
highlightedValue?string | null
The highlighted item's value. Pass it to control the highlight: the item takes the focus while the list has it, and the tab stop while it doesn't.
- Type
string | null
loopFocus?boolean
Whether arrow keys wrap from the last item to the first.
- Default
false
name?string
The name the value submits under.
orientation?"horizontal" | "vertical"
Which arrow keys move between items.
- Type
"horizontal" | "vertical"- Default
"vertical"
readOnly?boolean
Keeps the listbox focusable, but stops changes.
required?boolean
Blocks form submission until a value is selected.
scrollToIndexFn?(details: ListboxScrollToIndexDetails) → void
Brings the highlighted item into view, for a virtualized list that renders only some of the collection's items.
- Type
(details: ListboxScrollToIndexDetails) → void- Parameters
details– { immediate?: boolean; index: number }- Returns
void
selectionMode?SelectionMode
single selects one item, multiple toggles items, extended replaces
the selection unless Ctrl, ⌘ or Shift is held, and none only runs onSelect.
- Default
"single"
selectOnHighlight?boolean
Whether arrow keys and typing select the item they move to.
- Default
false
class?string
Merged with the part's classes.
@value-change(details: ListboxValueChangeDetails<T>) → void
Runs when the selection changes.
- Type
(details: ListboxValueChangeDetails<T>) → void- Parameters
details– ListboxValueChangeDetails<T>- Returns
void
@highlight-change(details: ListboxHighlightChangeDetails<T>) → void
Runs when focus moves to another item.
- Type
(details: ListboxHighlightChangeDetails<T>) → void- Parameters
details– ListboxHighlightChangeDetails<T>- Returns
void
@select(details: ListboxSelectionDetails) → void
Runs when an item is chosen, by a press or a key.
- Type
(details: ListboxSelectionDetails) → void- Parameters
details– { value: string }- Returns
void
ListboxLabel
<label> data-slot="listbox-label"
class?string
Merged with the part's classes.
data-disabled?string
Present when disabled is set.
ListboxContent
<div> data-slot="listbox"
class?string
Merged with the part's classes.
data-disabled?string
Present when the listbox is disabled, by its own prop, a Field or a <fieldset>.
data-has-icons?string
Present while any item inside holds an icon part, so items without one can line up.
data-orientation"vertical" | "horizontal"
Which arrow keys move between items.
- Type
"vertical" | "horizontal"
data-readonly?string
Present when the listbox is read-only.
data-required?string
Present when the listbox is required.
ListboxItem
<div> data-slot="listbox-item"
disabled?boolean
Keeps the item from being chosen. Defaults to the collection's for item.
- Default
itemDisabled
index?number
The item's position among all items, for virtualized lists that render only some. Sets aria-posinset and aria-setsize.
item?unknown
The collection item it shows; its value, text and disabled state come from the collection.
label?string
The text typing finds. Defaults to the collection's text for item.
- Default
(itemLabel || undefined)
value?string
The item's value, when it has no item.
variant?"default" | "destructive"
The visual style.
- Type
"default" | "destructive"- Default
"default"
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.
data-disabled?string
Present when the item can't be chosen. It can still be focused.
data-has-icon?string
Present on an item while it holds an icon part.
data-highlighted?string
Present on the item that has focus.
data-selected?string
Present on selected items, and on the check inside them.
data-state?string
Mirrors state.
data-variant?string
Mirrors variant.
ListboxItemText
<span> data-slot="listbox-item-text"
class?string
Merged with the part's classes.
ListboxItemGroup
<div> data-slot="listbox-group"
heading?string
The heading of the listbox item group.
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.
ListboxItemGroupLabel
<div> data-slot="listbox-group-label"
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.
ListboxSeparator
<div> data-slot="listbox-separator"
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.
ListboxValueText
<span> data-slot="listbox-value-text"
placeholder?string
What shows while nothing is selected.
class?string
Merged with the part's classes.
data-placeholder-shown?stringListboxItemIndicator
<span> data-slot="listbox-item-indicator"
keepMounted?boolean
Whether the indicator stays in the page while its item isn't selected, so it can be styled or animated in both states.
- Default
false
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.
data-selected?string
Present on selected items, and on the check inside them.
ListboxEmpty
<div> data-slot="listbox-empty"
class?string
Merged with the part's classes.
ListboxShortcut
<span> data-slot="listbox-shortcut"
class?string
Merged with the part's classes.











