Multi-select
Pick several options from a known list, with the chosen values shown as removable chips and an overflow count once they no longer fit.
Purpose
Several from a known list, searchably. The trigger shows each choice as a removable chip;
beyond maxVisible (default 3) the rest collapse into a "+N" badge. The list itself is a
search-filtered combobox, so it scales to long lists where a wall of checkboxes would not.
Triage the alternatives first: exactly one from a list is a Select or, searchable, a Combobox; values nobody can enumerate are a Tags input; and for five or fewer options that should all stay visible, a group of Checkboxes beats hiding them behind a click.
import { MultiSelect } from "@healthmetrics/ui/multi-select";
const [selected, setSelected] = React.useState<string[]>([]);
<MultiSelect
options={[
{ value: "gp", label: "Outpatient (GP)" },
{ value: "dental", label: "Dental" },
]}
value={selected}
onValueChange={setSelected}
placeholder="Select benefit types…"
/>Async options
While options load, pass loading to show a skeleton list in place of the options — the trigger
stays interactive so the layout does not jump when data lands:
const { data: clinics, isLoading } = useClinics();
<MultiSelect
options={clinics ?? []}
loading={isLoading}
value={selected}
onValueChange={setSelected}
placeholder="Select panel clinics…"
/>States
Empty, selected with overflow, loading, and disabled. disabled disables the trigger, so the
listbox cannot open. There is no error prop — present form-level errors through your form's
own error region.
Structure
| Property | Value |
|---|---|
| Trigger | outline Button, min-height 40px (min-h-10), grows as chips wrap |
| Chips | secondary Badge; remove target 24px square (size-6), 13px glyph |
| Overflow | outline "+N" Badge after maxVisible chips (default 3) |
| Caret | 18px unfold_more glyph, --muted-foreground |
| Placeholder | --muted-foreground |
| Listbox | --popover surface, width matches the trigger, zero padding |
| Option marker | 16px checkbox square; --primary fill + 13px check when selected |
| Loading | three skeleton lines in place of the options |
Best practices
Do
- Pair the trigger with a
Labelvia theidprop — chips are values, not a name for the field. - Keep
labeltext short — chips wrap and tall triggers push the form around. - Raise
maxVisibleonly when the field is wide; "+N" exists so ten choices do not become ten rows. - Pass
loadingwhile options fetch instead of rendering an empty list that says "No results found."
Don't
- Use it for a single choice — that is a Select or Combobox.
- Use it for open-ended values — options are a fixed list; free text is a Tags input.
- Hide 3 checkboxes behind it — few, fixed options belong visible on the page.
Accessibility & keyboard
- The trigger is a real button with
role="combobox"andaria-expanded; give the field a name with aLabelviaid. - Each chip's remove control is named "Remove label", operable with Enter or Space, and sized 24px square — the WCAG 2.2 AA minimum target (2.5.8).
- The list is a cmdk command menu: the search field takes focus on open and options are announced as they are filtered; the selected state is marked with a filled check square.
- The skeleton list is labelled "Loading options" while
loadingis set. - Selecting an option does not close the popover — deliberate, so several choices are one open-close cycle. Esc or clicking away closes.
- Keyboard: Enter or Space opens with focus in the search field; typing filters; arrow keys move through options; Enter toggles the highlighted option; Esc closes and returns focus to the trigger. On the trigger, Tab reaches each visible chip's remove control.
Props
Options are { value, label } pairs — label is what is displayed and searched.
| Prop | Type | Default | Description |
|---|---|---|---|
optionsrequired | MultiSelectOption[] | — | Selectable options. `label` is displayed and searched. |
value | string[] | undefined | — | Currently selected values (controlled). |
onValueChange | ((values: string[]) => void) | undefined | — | — |
loading | boolean | undefined | — | Show a skeleton option list while options load asynchronously. |
maxVisible | number | undefined | 3 | How many selected badges to show on the trigger before collapsing the rest into a "+N" badge. |
placeholder | string | undefined | "Select…" | — |
searchPlaceholder | string | undefined | "Search…" | — |
emptyText | string | undefined | "No results found." | — |
disabled | boolean | undefined | — | Disables the trigger; the listbox cannot open while set. |
className | string | undefined | — | — |
id | string | undefined | — | — |