Multi Select

Pick many options as removable tokens from a searchable panel.

Preview

"use client";

import { Circle } from "lucide-react";
import {
  MultiSelect,
  MultiSelectContent,
  MultiSelectEmpty,
  MultiSelectGroup,
  MultiSelectInput,
  MultiSelectItem,
  MultiSelectLabel,
  MultiSelectList,
  MultiSelectTrigger,
  MultiSelectValue,
} from "@/components/motion/multi-select";

const colors = {
  design: "fill-rose-500 text-rose-500",
  engineering: "fill-sky-500 text-sky-500",
  product: "fill-amber-500 text-amber-500",
  research: "fill-cyan-500 text-cyan-500",
  marketing: "fill-emerald-500 text-emerald-500",
  operations: "fill-slate-500 text-slate-500",
};

function Option({
  value,
  children,
}: {
  value: keyof typeof colors;
  children: string;
}) {
  return (
    <MultiSelectItem value={value} textValue={children}>
      <span className="flex items-center gap-2.5">
        <Circle aria-hidden="true" className={`size-2.5 ${colors[value]}`} />
        {children}
      </span>
    </MultiSelectItem>
  );
}

export function MultiSelectPreview() {
  return (
    <div className="flex min-h-[420px] w-full items-start justify-center px-4 pt-24">
      <div className="w-full max-w-sm">
        <MultiSelect defaultValue={["design", "engineering"]}>
          <MultiSelectTrigger>
            <MultiSelectValue placeholder="Choose teams" />
            <MultiSelectInput aria-label="Search teams" />
          </MultiSelectTrigger>
          <MultiSelectContent>
            <MultiSelectList ariaLabel="Teams">
              <MultiSelectGroup>
                <MultiSelectLabel>Product teams</MultiSelectLabel>
                <Option value="design">Design</Option>
                <Option value="engineering">Engineering</Option>
                <Option value="product">Product</Option>
                <Option value="research">Research</Option>
              </MultiSelectGroup>
              <MultiSelectGroup>
                <MultiSelectLabel>Business teams</MultiSelectLabel>
                <Option value="marketing">Marketing</Option>
                <Option value="operations">Operations</Option>
              </MultiSelectGroup>
              <MultiSelectEmpty>No teams found.</MultiSelectEmpty>
            </MultiSelectList>
          </MultiSelectContent>
        </MultiSelect>
      </div>
    </div>
  );
}

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @beui/multi-select

API Reference

MultiSelectContent

side?
"top" | "bottom"

Preferred side of the field to open on. Default: "bottom"

Defaultbottom
align?
"center" | "end" | "start"

Horizontal alignment against the field. Default: "start"

Defaultstart
sideOffset?
number

Gap between the field and the panel, in px. Default: 6

Default6
avoidCollisions?
boolean

Flip to the other side when there is more room there. Default: true

Defaulttrue
className?
string

Classes merged onto the panel element.

MultiSelect

value?
string[]

The selected values, for controlled use.

defaultValue?
string[]

The initial selected values when uncontrolled. Default: []

Default[]
onValueChange?
((value: string[]) => void)

Called with the new list of values when an option is added or removed.

open?
boolean

Whether the list is open, for controlled use.

defaultOpen?
boolean

Whether the list starts open when uncontrolled. Default: false

Defaultfalse
onOpenChange?
((open: boolean) => void)

Called with the new state when the list opens or closes.

query?
string

The search text, for controlled use.

defaultQuery?
string

The initial search text when uncontrolled. Default: ""

onQueryChange?
((query: string) => void)

Called with the new text when the search input changes.

filter?
OptionFilter

Decides which options match the search text.

Default(value, query, keywords) => { const needle = query.trim().toLocaleLowerCase(); if (!needle) return true; const haystack = [value, ...keywords].join(" ").toLocaleLowerCase(); let queryIndex = 0; for (const character of haystack) { if (character === needle[queryIndex]) queryIndex += 1; if (queryIndex === needle.length) return true; } return false; }
disabled?
boolean

Blocks opening and changing the selection. Default: false

Defaultfalse
className?
string

Classes merged onto the root element.

labels?
Partial<{ valuePlaceholder: string; removeValue: string; inputLabel: string; inputPlaceholder: string; listLabel: string; empty: string; }>

Override any built-in string. `{label}` fills the option label.

MultiSelectEmpty

className?
string

Classes merged onto the empty message.

MultiSelectGroup

className?
string

Classes merged onto the group fieldset.

MultiSelectItem

value
string

The option's value, added to or removed from the selection.

textValue?
string

Text for search and the trigger chip when the label is not plain text.

keywords?
string[]

Extra words that match this option in search.

Default[]
disabled?
boolean

Keeps the option visible but not selectable. Default: false

Defaultfalse
onSelect?
((value: string) => void)

Called with the option's value when it is clicked, before it toggles.

className?
string

Classes merged onto the option row.

MultiSelectLabel

className?
string

Classes merged onto the label element.

MultiSelectList

ariaLabel?
string

Accessible name for the listbox. Default: "Options"

className?
string

Classes merged onto the scrolling listbox.

MultiSelectSeparator

className?
string

Classes merged onto the separator line.

MultiSelectInput

ref?
Ref<HTMLInputElement>

Ref to the search input element.

showIcon?
boolean

Shows a search icon before the input. Default: false

Defaultfalse
className?
string

Classes merged onto the root element.

MultiSelectTrigger

className?
string

Classes merged onto the trigger element.

MultiSelectValue

placeholder?
ReactNode

Shown while nothing is selected and the list is closed. Default: "Select options"

className?
string

Classes merged onto the wrapper around the chips.

chipClassName?
string

Classes merged onto each selected value chip.

Also on React Native. Searchable options that become removable chips.

Updated