Back to elements
ElementForm & InputFree

Listbox React component

An always-open list for picking one or several options: a search box that filters as you type, sticky group headings, avatars and descriptions, a highlight that follows the pointer or keyboard, checks that draw in, and type-ahead to jump by name.

When to use the Listbox component

Use Listbox when the options should stay visible while people choose: assigning people, picking tags or categories, choosing items in a side panel or settings page.

For a compact field in a form, use Select, Combobox or Multi Select, which keep the list in a popover.

Installation

Add the Listbox component to your project with the shadcn CLI. It lands in components/listbox.tsx as plain React + Tailwind CSS source you own and can edit.

Install
Copied!
npx shadcn@latest add https://reactframe.com/r/listbox.json

Or copy the source by hand and install its dependencies:

Install
Copied!
npm install motion clsx tailwind-merge

Props

<Listbox /> accepts 11 props, all optional.

  • options
    { value: string; label: string; description?: string; group?: string; avatar?: string; disabled?: boolean }[]
    Default: DEFAULT_OPTIONS
  • multiple
    boolean
    Default: true
  • value
    string[]
  • defaultValue
    string[]
    Default: ["maya", "leo"]
  • onValueChange
    (value: string[]) => void
  • filter
    boolean
    Default: true
  • filterPlaceholder
    string
    Default: "Search people"
  • label
    string
    Default: "Assign to"
  • height

    Height of the scrolling list.

    number
    Default: 300
  • theme
    "dark" | "light"
    Default: "dark"
  • className
    string

FAQ

Can people search?
Yes. The search box filters by name and description as you type, and arrow keys work from inside it.
Does it support groups?
Give options a group and they're listed under sticky headings in the order the groups first appear.
How does keyboard selection work?
Arrow keys move the highlight, Space or Enter toggles, Home and End jump to the ends, and typing letters jumps to a matching name.

More Form & Input components

Toggle Button
Free
Knob
Free
Button Group
Free
Masked Input
Free
Dual Range Slider
Free
Input Group
Free