Components · Navigation
Command List
A search box over a filtered, grouped list you move through with the keyboard. Inline: put it in a Dialog, Sheet, Drawer or page.
import { CommandList } from '@nexub/react';Usage
Picking one item from a long list inside a dialog or sheet: move to folder, assign to, jump to.
A search the server answers (`onSearch` with `loading`).
An app-wide launcher opened with Cmd+K: use CommandPalette.
A form field that shows the picked value: use ComboboxField.
Ten choices or fewer: use a RadioGroup or Select.
Playground
Props
Picked: —
<CommandList items={items} onSelect={setPicked} autoFocus={false} />Examples
Default
In a dialog
Server search
States
- No results found.New invoiceNew customerReportsRevenue, cash flow and taxSettings
Picked: —
default - Loading…No results found.New invoiceNew customerReportsRevenue, cash flow and taxSettings
Picked: —
loading
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| itemsrequired | CommandListItem[] | — | { value, label, description?, keywords?, icon?, group?, disabled?, shortcut? }. description and keywords are searched too; group lists the item under a heading; shortcut shows keys at the end of the row. |
| onSelect | ((value: string, item: CommandListItem) => void) | — | Called when an item is picked with Enter or a click. |
| label | string | messages.search | Accessible name of the search box and list. |
| placeholder | string | messages.searchPlaceholder | The search box placeholder. |
| emptyText | React.ReactNode | messages.noResults | Shown when the search finds nothing. |
| onSearch | ((text: string) => void) | — | Server search: while onSearch is set the list is not filtered here. loading shows a busy row. |
| loading | boolean | — | Server search: while onSearch is set the list is not filtered here. loading shows a busy row. |
| autoFocus | boolean | true | Focus the search box on mount. |
| maxHeight | string | 20rem | The list scrolls past this height (any CSS length). |
| className | string | — |
Accessibility
Keyboard
- Arrow Up / Arrow Down
Moves the highlight; wraps at the ends.
- Home / End
Moves to the first or last item.
- Enter
Picks the highlighted item.
Notes
Focus stays in the search box, a `combobox` that points at the highlighted `option` with `aria-activedescendant`.
Group headings name their groups; disabled items are skipped and marked `aria-disabled`.
While loading, the list has `aria-busy`.