List Box
A List Box shows a set of options as a list that can be selected with the mouse or the keyboard, one at a time or several at once. Unlike a select it stays open, which suits a picker built into a panel, a file list or a settings column.
Rendered live, with the same build of the library you install.
Quarterly report.pdf2.4 MB · PDF
Budget.xlsx812 KB · Spreadsheet
Archive.zip18 MB · Archive
ListBox.tsx
import { useState } from 'react';import { NListBox } from '@nayan-ui/react';const items = [{ id: 'report', label: 'Quarterly report.pdf', description: '2.4 MB · PDF' },{ id: 'budget', label: 'Budget.xlsx', description: '812 KB · Spreadsheet' },{ id: 'archive', label: 'Archive.zip', description: '18 MB · Archive', disabled: true }];const ListBox = () => {const [selected, setSelected] = useState<any>(new Set(['report']));return (<div><NListBox items={items} selectionMode="multiple" selectedKeys={selected} onSelectionChange={setSelected} aria-label="Files" /></div>);};export default ListBox;
| Name | Type | Default | Details |
|---|---|---|---|
| items | NListBoxItem[] | Required | The items prop. |
| selectionMode | 'none' | 'single' | 'multiple' | 'single' | The selectionMode prop. |
| selectedKeys | Iterable<string> | Optional | The selectedKeys prop. |
| onSelectionChange | (keys: Selection) => void | Optional | The onSelectionChange prop. |
| onAction | (key: string) => void | Optional | Fires on click or Enter, for a list that acts rather than selects. |
| variant | 'default' | 'danger' | 'default' | The variant prop. |
| disabledKeys | Iterable<string> | Optional | Keys that cannot be chosen. Individual items can also carry `disabled`. |
| emptyMessage | ReactNode | 'Nothing here yet.' | Shown when `items` is empty. |
| className | string | '' | The className prop. |
| itemClassName | string | '' | The itemClassName prop. |
| aria-label | string | 'Options' | The aria-label prop. |
Other components solving nearby problems.