How it works
The field is filled like the text input and select, in three heights, and turns white with an accent halo while open. Selected values are round pills: white on the grey fill, grey once the field turns white. By default it is one row: hidden copies of the pills are measured to see how many fit, and the rest collapse into “+N”, so the height never changes. The panel has no portal: it hangs under the relative root at the field's width and flips above when there is not enough room below. Checking keeps it open. With a limit, unchecked options are dimmed once it is reached. A hidden input per value supports native form submission.
Use it for
- Choosing several from a fixed list in a form: assignees on a task, tags on a file, regions for a deployment.
- Multi-value filters on a list page, such as several statuses at once.
- Long or remote option lists: turn on searchable with onSearch and loading.
- Choices with a cap (at most 3 people): use maxCount so the field explains why nothing more can be picked.
Look elsewhere when
- Only one value: use a single select.
- Actions that run when picked: use a dropdown menu, which has menu semantics rather than a form value.
- Only 3-5 options: show a row of checkboxes so everything is visible.
- Free-form values that are not in the list: this component only picks from options.
- An ancestor with overflow: hidden and no room above or below: the panel has no portal and would be clipped.
Usage
import { useState } from 'react'
import { MultiSelect } from './MultiSelect.jsx'
const people = [
{ value: 'emma', label: 'Emma Clark', group: 'Design' },
{ value: 'liam', label: 'Liam Chen', group: 'Design' },
{ value: 'noah', label: 'Noah Evans (on leave)', group: 'Design', disabled: true },
{ value: 'mia', label: 'Mia Torres', group: 'Engineering' },
{ value: 'ethan', label: 'Ethan Brooks', group: 'Engineering' },
]
export function AssigneeField() {
const [value, setValue] = useState(['emma'])
return (
<div>
<label htmlFor="assignees">Assignees</label>
<MultiSelect
id="assignees"
options={people}
value={value}
onChange={setValue}
searchable
clearable
showSelectAll
maxCount={3}
placeholder="Type a name to search"
/>
</div>
)
}Props
| Prop | Type | Default | What it does |
|---|---|---|---|
options | { value, label, description?, disabled?, group? }[] | — | Options. value is a string or number and must be unique; neighboring options with the same group form a group. |
value | (string | number)[] | — | Controlled selected values; their order is the tag order. |
defaultValue | (string | number)[] | [] | Initial selected values when uncontrolled. |
onChange | (value, options) => void | — | Called on any change: checking, unchecking, removing a tag, Backspace, select all, clear. |
open | boolean | — | Controlled panel state; use with onOpenChange. |
defaultOpen | boolean | false | Initial panel state when uncontrolled; does not steal focus. |
onOpenChange | (open) => void | — | Called when the panel opens or closes. |
size | 'sm' | 'md' | 'lg' | 'md' | Single-row height 36 / 44 / 52px with 10 / 12 / 14px corners, pill height 24 / 28 / 36px, option rows 36 / 40 / 44px. Use lg on mobile. |
placeholder | string | 'Select' | Hint shown when nothing is selected. |
disabled | boolean | false | Disables the control: pills lose their remove buttons and an open panel closes. |
invalid | boolean | false | Danger hairline and tint, plus aria-invalid. Write the error text yourself and link it with aria-describedby. |
required | boolean | false | Sets aria-required; the asterisk is drawn by your form field. |
searchable | boolean | false | Puts an input after the tags to filter by typing. The query clears after a keyboard pick and stays after a mouse pick. |
onSearch | (query) => void | — | Called when the query changes (after IME composition ends, and once with an empty string on close). Fetch remote results here. |
filterOption | false | ((query, option) => boolean) | — | How to filter. Default: label contains the query, case-insensitive. Pass false for remote search. |
clearable | boolean | false | Shows a clear button when something can be removed. Its space is always reserved, so the field never resizes. |
loading | boolean | false | Shows only “Loading…” in the panel while options load. |
maxTagCount | number | 'auto' | 'auto' | Maximum tags shown, the rest collapse into “+N”. 'auto' measures the width in one-row mode and shows all when wrapping. |
wrap | boolean | false | Wraps tags onto more rows and grows the field; by default it keeps a single row. |
showSelectAll | boolean | false | Shows “Select all / Clear” and the selected count above the list. With maxCount only Clear is shown. |
maxCount | number | — | Maximum number of selections. Once reached, unchecked options are dimmed and a hint explains why. |
renderOption | (option, { selected, active, query }) => ReactNode | — | Custom content to the right of each checkbox, such as an avatar. Search highlighting is then up to you (the demo wraps the match in <mark className="ds-multiselect__match">). |
listHeight | number | 240 | Maximum height of the option list in px; it scrolls beyond that. |
emptyText | string | — | Text when there are no options. Defaults to the noMatch or empty label. |
labels | object | — | Replaces built-in text (remove, clear, selectAll, selectedCount, summary, options, loading, noMatch, empty, limit, limitReached). Shallow-merged over the English defaults. |
name | string | — | Renders a hidden <input name> per selected value, so native form submission includes them. |
ref | Ref<HTMLButtonElement | HTMLInputElement> | — | Forwarded to the focusable element: a <button>, or an <input> when searchable. |
...rest | HTMLAttributes<HTMLDivElement> | — | className, style and similar go to the root. id, autoFocus and aria-label / labelledby / describedby go to the focusable element, so <label htmlFor> works. Set --ds-multiselect-z for the panel layer. |
Accessibility
- Follows the WAI-ARIA combobox and listbox pattern: the focused element is a combobox with aria-expanded and aria-controls; the panel is a multiselectable listbox of options with aria-selected.
- Focus stays on the field and the highlighted option is exposed with aria-activedescendant; a hidden summary (“3 selected: …”) is linked with aria-describedby.
- Keys: Down / Up open and move (skipping disabled options), Home / End jump, PageUp / PageDown move 10, Enter toggles, Escape closes only the panel, Tab closes and moves on.
- Backspace on an empty input removes the last tag; Ctrl / ⌘ + A selects all when select all is on.
- On touch screens each option is at least 44px tall; with reduced motion the panel only fades and tags appear without scaling.
Motion
The panel enters in 220ms ease-out (from 6px toward the field and scale 0.96, with a fade, growing from the edge that touches the field) and leaves in 140ms ease-in. The field turns white and its accent halo grows in over 220ms. A newly checked pill pops in from scale 0.6 with a 320ms spring; the checkbox fills, springs back from a 0.88 press and its checkmark draws in 240ms; the limit hint turns warning-tinted and shakes for 240ms.
Add it to your project
Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the component next to your own.
MultiSelect.jsxmulti-select.csstokens.cssREADME.md
Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.





