Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Shadcn Listbox for React and Tailwind

Select a single or multiple items from a list.

Brazil
Mexico
Ireland

Installation

bunx --bun shadcn@latest add https://kit.dev/r/listbox.json

Anatomy

ListboxRoot
├── ListboxLabel
├── ListboxInput
├── ListboxItem
│   ├── ListboxItemText
│   ├── ListboxItemIndicator
│   └── ListboxItemGroup
│       └── ListboxItemGroupLabel
├── ListboxContent
└── ListboxValueText

Usage

import { createListCollection } from "@ark-ui/react/collection";
import {
  Listbox,
  ListboxContent,
  ListboxItem,
  ListboxItemIndicator,
  ListboxItemText,
} from "@/components/ui/listbox";
const Example = () => (
  <Listbox
    className="w-full max-w-64"
    collection={collection}
    defaultValue={["br"]}
  >
    <ListboxContent>
      {collection.items.map((item) => (
        <ListboxItem item={item} key={item.value}>
          <ListboxItemText>{item.label}</ListboxItemText>
          <ListboxItemIndicator />
        </ListboxItem>
      ))}
    </ListboxContent>
  </Listbox>
);

const collection = createListCollection({
  items: [
    { label: "Brazil", value: "br" },
    { label: "Mexico", value: "mx" },
    { label: "Ireland", value: "ie" },
  ],
});

Accessibility

KeyDescription
ArrowUp
Move up.
ArrowDown
Move down.
ArrowLeft
Move left.
ArrowRight
Move right.
Home
Go to the start.
End
Go to the end.
Enter
Activate the focused item.
CtrlA
Select all.
Space
Activate the focused item.
Escape
Clear the selection.

Demos

Controlled

Disabled

Disabled Item

Grid

Grouping

Horizontal

Image Explorer

Selection Extended

Selection Multiple

Selection None

Transfer List

With Description

With Filter

With Icon

With Popover

API Reference

ListboxItem

div

PropType
AttributeType

ListboxItemText

div

PropType
AttributeType

ListboxItemIndicator

div

PropType
AttributeType

ListboxItemGroup

div

PropType
AttributeType

ListboxItemGroupLabel

div

PropType
AttributeType

ListboxContent

div

PropType
AttributeType
CSS variableType

ListboxValueText

span

PropType
AttributeType

ListboxEmpty

div

PropType
AttributeType

ListboxShortcut

PropType
AttributeType

useListbox

PropType