# Select

Picks one value from a list. The trigger is the base Field box, and it sits in a Field for its label, hint and error; the list is a popout with the menu's rows. Built on ui-sdk's Select: arrow keys and typing move through it, Enter chooses, Escape closes, and the value submits with its form. A new choice crossfades into the field without changing its width, and a just-chosen row's tick draws itself in.

- Beta: ready to use; its API can still change in a minor release.
- Category: Form fields

```tsx
import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from "@leap-crm/design-system";
```

## Best practices

- Do: Use it to pick one value from a list a person can scan, like a matter type or a practice area. Use `Combobox` when people search by typing, like a contact by name.
- Do: Put `SelectSearch` first in a long list, like every matter type a firm has, and `SelectEmpty` after `SelectItems` to say when nothing matches.
- Do: Put the trigger in a `Field` for its label, hint and error. Alone, like a table filter, name it with `aria-label`.
- Do: Group items under a `SelectLabel` inside `SelectGroup`, like Recent above the full list, and divide groups with `SelectSeparator`.
- Don't: Use it for two or three options a person compares, like Yes or No. Use `RadioGroup` or `SegmentedControl`, so every choice shows without a click.
- Don't: Add a tick or check icon to `SelectItem`. The selected row already shows its tick on the right.

## Keyboard

| Keys | What they do |
| --- | --- |
| Enter, Space | Open the list and focus the first item. |
| Arrow keys | Move focus through the items, skipping disabled ones. |
| Home, End | Move to the first and last items. |
| Typing | Focuses the next item that starts with the text. |
| Enter, Space | Choose the focused item. |
| Escape | Closes without choosing and returns focus to the trigger. |

## Related

- [Combobox](./combobox.md)
- [Dropdown Menu](./dropdown-menu.md)
- [Radio](./radio.md)
- [Segmented Control](./segmented-control.md)

## Examples

What the examples import:

```tsx
import { Fragment } from "react";
import { Field, Select, SelectContent, SelectEmpty, SelectGroup, SelectItem, SelectItems, SelectLabel, SelectSearch, SelectSeparator, SelectTrigger, SelectValue } from "@leap-crm/design-system";
```

Scaffolding the examples call. It lives in the docs page, not in the library:

```tsx
const matterTypes = [
  "Conveyancing",
  "Family law",
  "Wills and estates",
  "Commercial",
  "Litigation",
] as const;

const sizes = ["xs", "sm", "md", "lg"] as const;

const allMatterTypes = [
  "Administrative law",
  "Body corporate",
  "Building and construction",
  "Commercial",
  "Commercial leasing",
  "Conveyancing",
  "Criminal law",
  "Debt recovery",
  "Employment",
  "Family law",
  "Immigration",
  "Insolvency",
  "Intellectual property",
  "Litigation",
  "Personal injury",
  "Planning and environment",
  "Powers of attorney",
  "Probate",
  "Wills and estates",
  "Workers compensation",
] as const;

function MatterType({
  size = "md",
  invalid = false,
  disabled = false,
  readOnly = false,
}: {
  size?: (typeof sizes)[number];
  invalid?: boolean;
  disabled?: boolean;
  readOnly?: boolean;
}) {
  return (
    <Select defaultValue="Conveyancing" disabled={disabled} readOnly={readOnly}>
      <Field
        label="Matter type"
        className="w-64"
        error={invalid ? "Please choose a matter type" : undefined}
      >
        <SelectTrigger size={size}>
          <SelectValue />
        </SelectTrigger>
      </Field>
      <SelectContent>
        {matterTypes.map(type => (
          <SelectItem key={type} value={type}>
            {type}
          </SelectItem>
        ))}
      </SelectContent>
    </Select>
  );
}
```

### Sizes

xs 28 · sm 32 · md 36 for forms · lg 40. Text and chevron scale with them.

```tsx
<div className="flex flex-col gap-4">
  {sizes.map(size => (
    <Fragment key={size}>
      <MatterType size={size} />
    </Fragment>
  ))}
</div>
```

### States

Hover darkens the border, keyboard focus is the blue edge and halo, an error turns it red (with a red halo on focus), read-only is grey and keeps its value, disabled is 50%.

```tsx
<div className="grid grid-cols-[repeat(auto-fill,minmax(16rem,1fr))] gap-6">
  <MatterType />
  <MatterType invalid />
  <MatterType readOnly />
  <MatterType disabled />
</div>
```

### Placeholder

Grey until something is chosen.

```tsx
<Select placeholder="Choose a matter type">
  <Field label="Matter type" className="w-64">
    <SelectTrigger>
      <SelectValue />
    </SelectTrigger>
  </Field>
  <SelectContent>
    {matterTypes.map(type => (
      <SelectItem key={type} value={type}>
        {type}
      </SelectItem>
    ))}
  </SelectContent>
</Select>
```

### Long list

A list taller than the room it has scrolls under the overlay scrollbar, which takes no space and fades when idle. Arrow keys keep the highlighted option in view.

```tsx
<Select placeholder="Choose a matter type">
  <Field label="Matter type" className="w-64">
    <SelectTrigger>
      <SelectValue />
    </SelectTrigger>
  </Field>
  <SelectContent className="max-h-72">
    {allMatterTypes.map(type => (
      <SelectItem key={type} value={type}>
        {type}
      </SelectItem>
    ))}
  </SelectContent>
</Select>
```

### Groups and search

A search field at the top filters the list, groups sit under quiet labels with a divider between them, and an empty search says so.

```tsx
<Select placeholder="Choose a responsible lawyer">
  <Field label="Responsible" className="w-64">
    <SelectTrigger>
      <SelectValue />
    </SelectTrigger>
  </Field>
  <SelectContent>
    <SelectSearch aria-label="Search staff" />
    <SelectItems>
      <SelectGroup>
        <SelectLabel>Conveyancing</SelectLabel>
        <SelectItem value="ada">Ada Hartley</SelectItem>
        <SelectItem value="ben">Ben Okafor</SelectItem>
      </SelectGroup>
      <SelectSeparator />
      <SelectGroup>
        <SelectLabel>Family law</SelectLabel>
        <SelectItem value="chloe">Chloe Nguyen</SelectItem>
        <SelectItem value="dev">Dev Patel</SelectItem>
      </SelectGroup>
    </SelectItems>
    <SelectEmpty>No one matches</SelectEmpty>
  </SelectContent>
</Select>
```

## Props

Select takes ui-sdk's options: value, defaultValue, onValueChange, multiple, placeholder, items, disabled, readOnly, required, name and the search options (query, filter, status). SelectContent takes side, align and alignItemWithTrigger.

### SelectTrigger

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | Usually a SelectValue. |
| `size` | `"xs" \| "sm" \| "md" \| "lg"` | `"md"` | xs 28 · sm 32 · md 36 for forms · lg 40. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### SelectValue

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### SelectContent

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | What it shows inside. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### SelectItem

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | What it shows inside. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### SelectLabel

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### SelectSearch

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
