Multi Select
newA searchable multi-select with badges in the field, groups, a create row and a limit.
Type to search. Backspace removes the last one.
Installation
npx shadcn@latest add @blank/multi-selectUsage
import { MultiSelect } from "@/components/ui/multi-select"<MultiSelect
options={[
{ value: "next", label: "Next.js" },
{ value: "astro", label: "Astro" },
]}
defaultValue={["next"]}
placeholder="Pick frameworks…"
/>The field is the search box: type to filter, arrow keys move through the list, Enter toggles, Backspace in an empty field drops the last pick. Picked options stay in the list with a check, so a second Enter undoes a pick.
Multi Select takes an options array and does the rest. When you need custom
rows or async data, compose Combobox with its chips
instead.
Examples
Groups, limit and creating options
Options with a group are listed under a heading. Once maxCount is
reached the remaining options dim, and picking one is refused through
onMaxCount, so the reason can show in FieldError.
creatable offers the typed text as a new option when nothing matches it
exactly.
Grouped options, up to three, and new labels on the fly.
API Reference
| Prop | Type | Default |
|---|---|---|
options | { value, label, disabled?, group? }[] | — |
value / defaultValue | string[] | [] |
onValueChange | (value: string[]) => void | — |
maxCount | number | — |
onMaxCount | (maxCount: number) => void | — |
creatable | boolean | false |
onCreateOption | (label: string) => string | void | — |
createLabel | (query: string) => ReactNode | Create "…" |
placeholder | string | — |
emptyMessage | ReactNode | "No results." |
size | "default" | "sm" | "default" |
open / defaultOpen / onOpenChange | list state | — |
id | string | — |
disabled | boolean | false |
name | string | — |
aria-invalid | boolean | — |