One choice, in place
import { ListBox } from "@senvenli/react/selection";
export default function Example() {
return (
<ListBox
label="Default view"
defaultSelectedKeys={["board"]}
items={[
{ id: "list", label: "List", icon: "list" },
{ id: "board", label: "Board", icon: "columns-3" },
{ id: "calendar", label: "Calendar", icon: "calendar" },
]}
/>
);
}import { ListBox } from "@senvenli/react/selection";Examples
Several
`selectionMode="multiple"`: Space toggles an option.import { ListBox } from "@senvenli/react/selection";
export default function Example() {
return (
<ListBox
label="Notify me about"
selectionMode="multiple"
defaultSelectedKeys={["orders"]}
items={[
{ id: "orders", label: "New orders", description: "As they come in" },
{ id: "payments", label: "Payments", description: "Received and failed" },
{ id: "reviews", label: "Reviews", description: "Once a day" },
]}
/>
);
}Guidelines
When to use it
- A short set of options that should stay visible: a settings choice, a filter list.
Use something else when
- The choice can live in a dropdown. Select
- Rows of content with their own actions. Grid list
- Two to five options with a line of detail. Radio group
Do and avoid
- Label it; keep options short.
Accessibility
Built in
- Arrows move, typing jumps to an option, Space selects; selected options are marked and say so.
You provide
- A label (or aria-label).
API reference
ListBox
| Prop | Type | Default | Description |
|---|---|---|---|
label | React.ReactNode | – | The visible name of the list. Leave it out only with an |
aria-label | string | – | |
itemsRequired | readonly ListBoxOption[] | – | |
selectionMode | "none" | "single" | "multiple" | "single" |
|
selectedKeys | Iterable<Key> | – | |
defaultSelectedKeys | Iterable<Key> | – | |
onSelectionChange | (keys: Selection) => void | – | |
onAction | (key: Key) => void | – | With |
emptyState | React.ReactNode | – | Shown inside the list when it has no options: a sentence or an |
labelReact.ReactNodeThe visible name of the list. Leave it out only with an
aria-label.aria-labelstringitemsRequiredreadonly ListBoxOption[]selectionMode"none" | "single" | "multiple"Default"single"single(default),multipleornone(a list of actions withonAction).selectedKeysIterable<Key>defaultSelectedKeysIterable<Key>onSelectionChange(keys: Selection) => voidonAction(key: Key) => voidWith
selectionMode="none": what pressing an option does.emptyStateReact.ReactNodeShown inside the list when it has no options: a sentence or an
EmptyState.