ValyroUI Русская версия

Listbox

Option list on the page: one or several, Shift ranges. Free, MIT · Forms and input › Selects

A list of options that stays on the page (WAI-ARIA listbox, React Aria's ListBox): one or several selected, the arrows, Home / End, Page keys and type-ahead move the highlight, and with multiple Shift+click and Shift+arrows select ranges. Props not listed go to the listbox element.

Installation

npx valyro-cli@latest add listbox
npx shadcn@latest add https://valyro.xyz/r/listbox.json
npm install valyro-ui

import 'valyro-ui/styles.css';
import { Listbox } from 'valyro-ui';

Props

PropTypeDefault
optionsSelectItem[]Options, flat or in labelled groups. Or compose them as children: Listbox.Item, Listbox.Group, Listbox.Empty.
childrenReactNodeThe compound form instead of options: Listbox.Item, Listbox.Group and Listbox.Empty elements.
multiplebooleanfalseSeveral options can be selected: checkboxes, Shift ranges, Ctrl/Cmd+A, Escape to clear.
valuestring[]Selected values (at most one without multiple), in the order they were picked.
defaultValuestring[]Initial value when uncontrolled.
onValueChange(value: string[]) => voidCalled with the new value when it changes.
selectionBehavior'toggle' | 'replace'toggle (default): a click, Enter or Space picks or toggles an option, the arrows only move. replace: a click or an arrow selects that option alone, as in a file list; Ctrl/Cmd+click and Ctrl/Cmd+Space add or remove one.
emptyTextReactNodeShown instead of the list when there are no options; announced politely.
namestringSubmits the selected values with the surrounding form, one hidden input each.
requiredbooleanAt least one option must be selected: aria-required, and the surrounding form does not submit without one.
disabledbooleanfalseEvery option is disabled and the list leaves the tab order.
invalidbooleanfalseError border and aria-invalid (an explicit aria-invalid wins).

Compound parts

Listbox.Item (ListboxItem), Listbox.Group (ListboxGroup), Listbox.Empty (ListboxEmpty)

Related components

Previous: Combobox · Next: Chip Group · All Forms and input