# Select

Pick one option from a short list in a dropdown, with groups, descriptions and icons.

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

## Example: A short list

One option from a handful, under a visible label.

```tsx
import { Select } from "@senvenli/react/selection";

export default function Example() {
  return (
    <div className="max-w-80">
      <Select
        label="Status"
        placeholder="Choose a status"
        defaultSelectedKey="in-progress"
        items={[
          { id: "draft", label: "Draft" },
          { id: "in-progress", label: "In progress" },
          { id: "in-review", label: "In review" },
          { id: "done", label: "Done" },
        ]}
      />
    </div>
  );
}
```

## Examples

### Groups, descriptions and details

Options under headers, with a second line and a right-aligned detail.

```tsx
import { Select } from "@senvenli/react/selection";

export default function Example() {
  return (
    <div className="max-w-80">
      <Select
        label="Assign to"
        placeholder="Choose a team"
        description="The team is notified by email."
        items={[
          { id: "support-1", label: "Tier 1", description: "First response", meta: "8 people", group: "Support" },
          { id: "support-2", label: "Tier 2", description: "Escalations", meta: "3 people", group: "Support" },
          { id: "billing", label: "Billing", description: "Invoices and refunds", meta: "4 people", group: "Finance" },
          { id: "fraud", label: "Fraud review", description: "Paused until Monday", meta: "2 people", group: "Finance", isDisabled: true },
        ]}
      />
    </div>
  );
}
```

### Compact

The 32px size for table filters and toolbars, named by aria-label.

```tsx
import { Stack } from "@senvenli/react/layout";
import { Select } from "@senvenli/react/selection";
import { useState } from "react";

export default function Example() {
  const [period, setPeriod] = useState<string | number | null>("30");
  return (
    <Stack direction="horizontal" space="space-100">
      <Select
        aria-label="Period"
        size="small"
        selectedKey={period}
        onSelectionChange={setPeriod}
        items={[
          { id: "7", label: "Last 7 days" },
          { id: "30", label: "Last 30 days" },
          { id: "90", label: "Last 90 days" },
        ]}
      />
      <Select
        aria-label="Channel"
        size="small"
        placeholder="All channels"
        items={[
          { id: "online", label: "Online" },
          { id: "retail", label: "Retail" },
        ]}
      />
    </Stack>
  );
}
```

### Invalid and disabled

An error under the field, and a field that cannot change.

```tsx
import { Stack } from "@senvenli/react/layout";
import { Select } from "@senvenli/react/selection";

const CURRENCIES = [
  { id: "usd", label: "US dollar" },
  { id: "eur", label: "Euro" },
  { id: "gbp", label: "Pound sterling" },
];

export default function Example() {
  return (
    <div className="max-w-80">
      <Stack space="space-300">
        <Select label="Invoice currency" isRequired isInvalid errorMessage="Choose the currency this customer pays in." items={CURRENCIES} />
        <Select label="Account currency" description="Set when the account was created." isDisabled defaultSelectedKey="usd" items={CURRENCIES} />
      </Stack>
    </div>
  );
}
```

### Several: A few options

Each choice shows as a tag that can be removed.

```tsx
import { Select } from "@senvenli/react/selection";

export default function Example() {
  return (
    <div className="max-w-80">
      <Select selectionMode="multiple"
        label="Notify by"
        placeholder="Add channel"
        defaultSelectedKeys={["email"]}
        items={[
          { id: "email", label: "Email" },
          { id: "sms", label: "Text message" },
          { id: "push", label: "Push notification" },
          { id: "slack", label: "Slack", description: "Posts to #orders" },
        ]}
      />
    </div>
  );
}
```

### Several: Select all, with collapsed tags

A footer selects everything; tags past the limit fold into a count.

```tsx
import { Select } from "@senvenli/react/selection";

const REGIONS = [
  { id: "na", label: "North America" },
  { id: "sa", label: "South America" },
  { id: "eu", label: "Europe" },
  { id: "me", label: "Middle East" },
  { id: "af", label: "Africa" },
  { id: "apac", label: "Asia Pacific" },
];

export default function Example() {
  return (
    <div className="max-w-80">
      <Select selectionMode="multiple"
        label="Regions"
        description="Orders from these regions appear in the report."
        allowsSelectAll
        maxVisibleTags={2}
        defaultSelectedKeys={["na", "eu", "apac", "me"]}
        items={REGIONS}
      />
    </div>
  );
}
```

### Several: Invalid and disabled

The app's own error under the field, and a field that cannot change.

```tsx
import { Stack } from "@senvenli/react/layout";
import { Select } from "@senvenli/react/selection";
import { useState } from "react";

const ROLES = [
  { id: "admin", label: "Admin" },
  { id: "billing", label: "Billing" },
  { id: "support", label: "Support" },
];

export default function Example() {
  const [roles, setRoles] = useState<(string | number)[]>([]);
  return (
    <div className="max-w-80">
      <Stack space="space-300">
        <Select selectionMode="multiple"
          label="Roles"
          isRequired
          requiredValidation="app"
          isInvalid={roles.length === 0}
          errorMessage="Choose at least one role."
          selectedKeys={roles}
          onSelectionChange={setRoles}
          items={ROLES}
        />
        <Select selectionMode="multiple" label="Inherited roles" isDisabled defaultSelectedKeys={["support"]} items={ROLES} />
      </Stack>
    </div>
  );
}
```

## Guidelines

### When to use it

- One choice from about 5 to 15 options.
- Several choices from a medium list.

### Use something else when

- [radio](https://design.senvenli.com/docs/components/radio.md): Fewer than 5 options should all stay visible.
- [combobox](https://design.senvenli.com/docs/components/combobox.md): The list is long and people type to find.
- [checkbox](https://design.senvenli.com/docs/components/checkbox.md): A few options should all stay visible.
- [list-box](https://design.senvenli.com/docs/components/list-box.md): The options should stay visible on the page, not in a dropdown.

## Accessibility

Keyboard:

- Space, Enter, Arrow down: Opens the list.
- Arrow keys, typing: Moves to an option.

Built in:

- Announced as a button that opens a listbox.
- Required fields show "Fill in this field." after a blur or a submit; your own `errorMessage` replaces it.
- Each tag has a remove button named after its option.

You provide:

- A visible label.

## API reference

### Select

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| label | `React.ReactNode` |  | no | The label sits above the field. |
| items | `readonly SelectItem[]` |  | yes | Up to ~15 options; more, or options people know by name → ComboBox. |
| selectedKey | `Key` |  | no | Controlled value; `null` is "nothing chosen". It may start undefined and become set later. |
| defaultSelectedKey | `Key` |  | no |  |
| onSelectionChange | `(key: Key \| null) => void \| (keys: Key[]) => void` |  | no |  |
| placeholder | `string` |  | no | Defaults to "Select" in the provider locale. |
| description | `React.ReactNode` |  | no |  |
| errorMessage | `React.ReactNode` |  | no |  |
| isInvalid | `boolean` |  | no |  |
| aria-invalid | `boolean \| "true" \| "false"` |  | no | Set by a form row that owns the error text (the shared `Field` hands its control `aria-invalid`): the field shows its invalid state as with `isInvalid`, and without an `errorMessage` of its own draws no error row, so the row's message is the only one. The trigger is a button, on which React Aria sets no `aria-invalid`: the forwarded invalid state shows as `data-invalid` on the field (its danger border) and through the row's own error text, not as `aria-invalid` on the trigger. It marks the field invalid for styling and assistive tech only: unlike `isInvalid` it never becomes the field's native validity (React Aria's default outside a DS Form), so it never blocks a form's submit. |
| isRequired | `boolean` |  | no |  |
| requiredValidation | `RequiredValidation` |  | no | Who says an empty required Select is missing: `field` (default) shows "Fill in this field." on blur and on a DS Form submit, which it then blocks; `app` only marks the field (`*`, `aria-required`) and the app shows its own error. See {@link RequiredValidation}. The app's `isInvalid` (`true` with its `errorMessage`, or `false`) overrides the check, as on TextField. Disabled, empty and required, it still blocks a DS Form's submit and cannot take focus (as TextField). |
| isDisabled | `boolean` |  | no |  |
| size | `FieldSize` |  | no | `compact` (32px) for table filters and toolbars. |
| name | `string` |  | no |  |
| selectionMode | `"single" \| "multiple"` |  | no | `single` (default): one choice from a known list. |
| radius | `ComponentRadius` |  | no | Corner radius: `none`, `small`, `medium` (the design), `large` or `full`. The provider's default otherwise. |
| aria-label | `string` |  | no | Names the field for assistive technology when no visible label is shown. |
| selectedKeys | `readonly Key[]` |  | no | Controlled; may start undefined and become set later (never flips control). |
| defaultSelectedKeys | `readonly Key[]` |  | no |  |
| maxVisibleTags | `number` |  | no | Tags shown before the rest collapse into "+3". |
| allowsSelectAll | `boolean` |  | no | Adds the "Select all" footer with the selected count. |

### Tokens it reads

`--ds-background-brand-bold`, `--ds-background-disabled`, `--ds-background-input`, `--ds-background-input-hovered`, `--ds-background-neutral`, `--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-icon-subtle`, `--ds-link`, `--ds-radius-control-medium`, `--ds-radius-control-small`, `--ds-radius-full`, `--ds-radius-large`, `--ds-radius-medium`, `--ds-radius-small`, `--ds-radius-xsmall`, `--ds-shadow-overlay`, `--ds-shadow-raised`, `--ds-size-control`, `--ds-size-control-compact`, `--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

- [combobox](https://design.senvenli.com/docs/components/combobox.md)
- [radio](https://design.senvenli.com/docs/components/radio.md)
- [tag-group](https://design.senvenli.com/docs/components/tag-group.md)
