# List box

A list of options shown in place, not in a dropdown: pick one or several.

- Family: selection
- Import: `import { ListBox } from "@senvenli/react/selection";`
- Page: https://design.senvenli.com/docs/components/list-box
- JSON: https://design.senvenli.com/docs/components/list-box.json

## Example: One choice, in place

The options stay visible; the chosen one is marked.

```tsx
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" },
      ]}
    />
  );
}
```

## Examples

### Several

`selectionMode="multiple"`: Space toggles an option.

```tsx
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

- [select](https://design.senvenli.com/docs/components/select.md): The choice can live in a dropdown.
- [grid-list](https://design.senvenli.com/docs/components/grid-list.md): Rows of content with their own actions.
- [radio](https://design.senvenli.com/docs/components/radio.md): Two to five options with a line of detail.

### 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 | Required | Description |
| --- | --- | --- | --- | --- |
| label | `React.ReactNode` |  | no | The visible name of the list. Leave it out only with an `aria-label`. |
| aria-label | `string` |  | no |  |
| items | `readonly ListBoxOption[]` |  | yes |  |
| selectionMode | `"none" \| "single" \| "multiple"` | `"single"` | no | `single` (default), `multiple` or `none` (a list of actions with `onAction`). |
| selectedKeys | `Iterable<Key>` |  | no |  |
| defaultSelectedKeys | `Iterable<Key>` |  | no |  |
| onSelectionChange | `(keys: Selection) => void` |  | no |  |
| onAction | `(key: Key) => void` |  | no | With `selectionMode="none"`: what pressing an option does. |
| emptyState | `React.ReactNode` |  | no | Shown inside the list when it has no options: a sentence or an `EmptyState`. |

### Tokens it reads

`--ds-background-brand-bold`, `--ds-background-disabled`, `--ds-background-input`, `--ds-background-neutral-pressed`, `--ds-background-neutral-subtle-hovered`, `--ds-background-selected`, `--ds-background-selected-hovered`, `--ds-border`, `--ds-border-bold`, `--ds-border-danger`, `--ds-border-focused`, `--ds-border-selected`, `--ds-easing-standard`, `--ds-radius-full`, `--ds-radius-large`, `--ds-radius-small`, `--ds-radius-xsmall`, `--ds-shadow-overlay`, `--ds-shadow-raised`, `--ds-space-025`, `--ds-space-050`, `--ds-space-075`, `--ds-space-100`, `--ds-space-150`, `--ds-space-200`, `--ds-surface-overlay`, `--ds-surface-raised`, `--ds-text`, `--ds-text-disabled`, `--ds-text-on-brand`, `--ds-text-subtle`, `--ds-text-subtlest`

## Related

- [select](https://design.senvenli.com/docs/components/select.md)
- [grid-list](https://design.senvenli.com/docs/components/grid-list.md)
- [radio](https://design.senvenli.com/docs/components/radio.md)
