ComponentsForm
Multi-select
A select-like field whose list lets people choose several options; the field shows them as labels, chips or a count.
Import
import { MultiSelect, MultiSelectCollection, MultiSelectContent, MultiSelectEmpty, MultiSelectGroup, MultiSelectItem, MultiSelectLabel, MultiSelectList, MultiSelectSeparator, MultiSelectTrigger, MultiSelectValue } from "@booleanpress/ui/multi-select"Also install @base-ui/react: pnpm add @base-ui/react
Usage
MultiSelect is Base UI's Combobox with multiple and its input inside the list, behind a trigger with Select's look. It needs the @base-ui/react peer package. For a single choice use Select; to type the values into the field itself, use Combobox with multiple.
import { Label } from "@booleanpress/ui/label"
import {
MultiSelect,
MultiSelectContent,
MultiSelectItem,
MultiSelectList,
MultiSelectTrigger,
MultiSelectValue,
} from "@booleanpress/ui/multi-select"
const EVENTS = ["Delivered", "Bounced", "Complained", "Opened"]
export function EventsField() {
return (
<>
<Label htmlFor="events">Webhook events</Label>
<MultiSelect items={EVENTS} defaultValue={["Bounced"]}>
<MultiSelectTrigger id="events" className="w-full">
<MultiSelectValue placeholder="Choose events" />
</MultiSelectTrigger>
<MultiSelectContent>
<MultiSelectList>
{(event: string) => (
<MultiSelectItem key={event} value={event}>
{event}
</MultiSelectItem>
)}
</MultiSelectList>
</MultiSelectContent>
</MultiSelect>
</>
)
}It is uncontrolled with defaultValue, or controlled with value and onValueChange, which carry an array of the chosen options (strings, or { value, label } objects, whose label the field shows). MultiSelectValue shows the choice: display="labels" (the default) joins the labels with commas, "chips" shows a chip for each with a ร to remove it, "count" says "3 selected"; maxShown stops after that many and adds "+2 more". On the trigger, size, variant="filled", fluid and clearable work as on Select's trigger. With name, each chosen option is submitted as a hidden input (an object by its value), none while disabled; a form reset brings back defaultValue.
The list keeps a filter field at its top: typing always filters, and the field appears once something is typed; filter on MultiSelectContent shows it from the start. selectAll adds a checkbox that chooses every option the filter leaves, or clears them. indicator="checkbox" on an item draws a checkbox where the check would be. Picking keeps the list open and the filter in place, so several options can be picked from one search. Inside a Dialog, Sheet or Popover the list renders inside that overlay, within its focus trap, since focus moves into the list; Escape closes the list before the overlay.
Examples
Basic
The chosen labels, joined with commas; each chosen option is filled with a check at its start.
import { Label } from "@booleanpress/ui/label"
import {
MultiSelect,
MultiSelectContent,
MultiSelectItem,
MultiSelectList,
MultiSelectTrigger,
MultiSelectValue,
} from "@booleanpress/ui/multi-select"
const EVENTS = ["Delivered", "Bounced", "Complained", "Opened", "Clicked", "Unsubscribed", "Deferred", "Failed"]
export default function MultiSelectBasic() {
return (
<div className="flex w-full max-w-56 flex-col gap-2">
<Label htmlFor="multi-select-events">Webhook events</Label>
<MultiSelect items={EVENTS}>
<MultiSelectTrigger id="multi-select-events" className="w-full">
<MultiSelectValue placeholder="Choose events" />
</MultiSelectTrigger>
<MultiSelectContent>
<MultiSelectList>
{(event: string) => (
<MultiSelectItem key={event} value={event}>
{event}
</MultiSelectItem>
)}
</MultiSelectList>
</MultiSelectContent>
</MultiSelect>
</div>
)
}Chips
display="chips": a chip per choice, its ร removes it with the pointer; the field grows a row when the chips wrap.
import { Label } from "@booleanpress/ui/label"
import {
MultiSelect,
MultiSelectContent,
MultiSelectItem,
MultiSelectList,
MultiSelectTrigger,
MultiSelectValue,
} from "@booleanpress/ui/multi-select"
const AGENTS = [
{ value: "sc", label: "Sara Chowdhury" },
{ value: "ar", label: "Arif Rahman" },
{ value: "jk", label: "Jonas Keller" },
{ value: "tm", label: "Tamsin Moore" },
{ value: "lb", label: "Lena Brandt" },
]
export default function MultiSelectChips() {
return (
<div className="flex w-full max-w-md flex-col gap-2">
<Label htmlFor="multi-select-agents">Notify these agents</Label>
<MultiSelect items={AGENTS} defaultValue={[AGENTS[0], AGENTS[2]]}>
<MultiSelectTrigger id="multi-select-agents" fluid>
<MultiSelectValue display="chips" placeholder="Choose agents" />
</MultiSelectTrigger>
<MultiSelectContent>
<MultiSelectList>
{(agent: (typeof AGENTS)[number]) => (
<MultiSelectItem key={agent.value} value={agent}>
{agent.label}
</MultiSelectItem>
)}
</MultiSelectList>
</MultiSelectContent>
</MultiSelect>
</div>
)
}Checkbox selection
indicator="checkbox" on the items and selectAll on the list: a checkbox at the top chooses or clears them all.
import { Label } from "@booleanpress/ui/label"
import {
MultiSelect,
MultiSelectContent,
MultiSelectItem,
MultiSelectList,
MultiSelectTrigger,
MultiSelectValue,
} from "@booleanpress/ui/multi-select"
const SITES = ["shop.example.com", "blog.example.com", "docs.example.com", "status.example.com", "help.example.com"]
export default function MultiSelectCheckbox() {
return (
<div className="flex w-full max-w-56 flex-col gap-2">
<Label htmlFor="multi-select-sites">Send from these sites</Label>
<MultiSelect items={SITES} defaultValue={["shop.example.com"]}>
<MultiSelectTrigger id="multi-select-sites" className="w-full">
<MultiSelectValue placeholder="Choose sites" />
</MultiSelectTrigger>
<MultiSelectContent selectAll>
<MultiSelectList>
{(site: string) => (
<MultiSelectItem key={site} value={site} indicator="checkbox">
{site}
</MultiSelectItem>
)}
</MultiSelectList>
</MultiSelectContent>
</MultiSelect>
</div>
)
}Filter
filter shows the filter field from the start; MultiSelectEmpty says "No results" when nothing matches.
import { Label } from "@booleanpress/ui/label"
import {
MultiSelect,
MultiSelectContent,
MultiSelectEmpty,
MultiSelectItem,
MultiSelectList,
MultiSelectTrigger,
MultiSelectValue,
} from "@booleanpress/ui/multi-select"
const COUNTRIES = ["Australia", "Bangladesh", "Brazil", "Canada", "Egypt", "France", "Germany", "India", "Japan", "Spain"]
export default function MultiSelectFilter() {
return (
<div className="flex w-full max-w-56 flex-col gap-2">
<Label htmlFor="multi-select-countries">Block sign-ups from</Label>
<MultiSelect items={COUNTRIES}>
<MultiSelectTrigger id="multi-select-countries" className="w-full">
<MultiSelectValue placeholder="Choose countries" />
</MultiSelectTrigger>
<MultiSelectContent filter filterPlaceholder="Filter countries">
<MultiSelectEmpty />
<MultiSelectList>
{(country: string) => (
<MultiSelectItem key={country} value={country}>
{country}
</MultiSelectItem>
)}
</MultiSelectList>
</MultiSelectContent>
</MultiSelect>
</div>
)
}Groups
Grouped items with MultiSelectGroup and MultiSelectLabel.
import { Label } from "@booleanpress/ui/label"
import {
MultiSelect,
MultiSelectContent,
MultiSelectGroup,
MultiSelectItem,
MultiSelectLabel,
MultiSelectList,
MultiSelectTrigger,
MultiSelectValue,
} from "@booleanpress/ui/multi-select"
const GROUPS = [
{ value: "Delivery", items: ["Delivered", "Deferred", "Bounced", "Failed"] },
{ value: "Engagement", items: ["Opened", "Clicked", "Unsubscribed", "Complained"] },
]
export default function MultiSelectGroups() {
return (
<div className="flex w-full max-w-56 flex-col gap-2">
<Label htmlFor="multi-select-groups">Log these events</Label>
<MultiSelect items={GROUPS} defaultValue={["Bounced", "Complained"]}>
<MultiSelectTrigger id="multi-select-groups" className="w-full">
<MultiSelectValue placeholder="Choose events" />
</MultiSelectTrigger>
<MultiSelectContent>
<MultiSelectList>
{(group: (typeof GROUPS)[number]) => (
<MultiSelectGroup key={group.value} items={group.items}>
<MultiSelectLabel>{group.value}</MultiSelectLabel>
{group.items.map((event) => (
<MultiSelectItem key={event} value={event}>
{event}
</MultiSelectItem>
))}
</MultiSelectGroup>
)}
</MultiSelectList>
</MultiSelectContent>
</MultiSelect>
</div>
)
}Max shown
maxShown={1} shows the first label and "+2 more"; display="count" says "3 selected".
import { Label } from "@booleanpress/ui/label"
import {
MultiSelect,
MultiSelectContent,
MultiSelectItem,
MultiSelectList,
MultiSelectTrigger,
MultiSelectValue,
} from "@booleanpress/ui/multi-select"
const LABELS = ["Billing", "Delivery", "Integrations", "Account", "Deliverability", "API", "Refunds"]
export default function MultiSelectMaxShown() {
return (
<div className="flex w-full max-w-60 flex-col gap-4">
<div className="flex flex-col gap-2">
<Label htmlFor="multi-select-max">Ticket labels</Label>
<MultiSelect items={LABELS} defaultValue={["Billing", "Refunds", "Account"]}>
<MultiSelectTrigger id="multi-select-max" className="w-full">
<MultiSelectValue maxShown={1} placeholder="Choose labels" />
</MultiSelectTrigger>
<MultiSelectContent>
<MultiSelectList>
{(label: string) => (
<MultiSelectItem key={label} value={label}>
{label}
</MultiSelectItem>
)}
</MultiSelectList>
</MultiSelectContent>
</MultiSelect>
</div>
<div className="flex flex-col gap-2">
<Label htmlFor="multi-select-count">Ticket labels, as a count</Label>
<MultiSelect items={LABELS} defaultValue={["Delivery", "API", "Integrations"]}>
<MultiSelectTrigger id="multi-select-count" className="w-full">
<MultiSelectValue display="count" placeholder="Choose labels" />
</MultiSelectTrigger>
<MultiSelectContent>
<MultiSelectList>
{(label: string) => (
<MultiSelectItem key={label} value={label}>
{label}
</MultiSelectItem>
)}
</MultiSelectList>
</MultiSelectContent>
</MultiSelect>
</div>
</div>
)
}Clear
clearable shows a clear button while options are chosen; it empties the choice and keeps focus on the field.
import { useState } from "react"
import { Label } from "@booleanpress/ui/label"
import {
MultiSelect,
MultiSelectContent,
MultiSelectItem,
MultiSelectList,
MultiSelectTrigger,
MultiSelectValue,
} from "@booleanpress/ui/multi-select"
const STATUSES = ["Open", "Pending", "On hold", "Solved", "Closed"]
export default function MultiSelectClear() {
const [statuses, setStatuses] = useState(["Open", "Pending"])
return (
<div className="flex w-full max-w-56 flex-col gap-2">
<Label htmlFor="multi-select-status">Ticket status</Label>
<MultiSelect items={STATUSES} value={statuses} onValueChange={setStatuses}>
<MultiSelectTrigger id="multi-select-status" clearable className="w-full">
<MultiSelectValue placeholder="Any status" />
</MultiSelectTrigger>
<MultiSelectContent>
<MultiSelectList>
{(status: string) => (
<MultiSelectItem key={status} value={status}>
{status}
</MultiSelectItem>
)}
</MultiSelectList>
</MultiSelectContent>
</MultiSelect>
<p className="text-xs text-muted-foreground">
{statuses.length ? `Showing ${statuses.length} of ${STATUSES.length} statuses.` : "Showing every ticket."}
</p>
</div>
)
}Sizes
sm is 28 px high, default 35 px and lg 42 px.
import {
MultiSelect,
MultiSelectContent,
MultiSelectItem,
MultiSelectList,
MultiSelectTrigger,
MultiSelectValue,
} from "@booleanpress/ui/multi-select"
const SIZES = [
{ size: "sm", label: "Small" },
{ size: "default", label: "Default" },
{ size: "lg", label: "Large" },
] as const
const REGIONS = ["Europe (Ireland)", "Europe (Frankfurt)", "US East (N. Virginia)", "Asia Pacific (Mumbai)"]
export default function MultiSelectSizes() {
return (
<div className="flex w-full max-w-56 flex-col gap-4">
{SIZES.map(({ size, label }) => (
<MultiSelect key={size} items={REGIONS}>
<MultiSelectTrigger size={size} aria-label={`Regions, ${label.toLowerCase()} size`} className="w-full">
<MultiSelectValue placeholder={label} />
</MultiSelectTrigger>
<MultiSelectContent>
<MultiSelectList>
{(region: string) => (
<MultiSelectItem key={region} value={region}>
{region}
</MultiSelectItem>
)}
</MultiSelectList>
</MultiSelectContent>
</MultiSelect>
))}
</div>
)
}Filled
variant="filled" fills the field with the grey --field-filled, on hover and focus too.
import { Label } from "@booleanpress/ui/label"
import {
MultiSelect,
MultiSelectContent,
MultiSelectItem,
MultiSelectList,
MultiSelectTrigger,
MultiSelectValue,
} from "@booleanpress/ui/multi-select"
const CHANNELS = ["Email", "SMS", "Slack", "Webhook"]
export default function MultiSelectFilled() {
return (
<div className="flex w-full max-w-56 flex-col gap-2">
<Label htmlFor="multi-select-channels">Alert channels</Label>
<MultiSelect items={CHANNELS}>
<MultiSelectTrigger id="multi-select-channels" variant="filled" className="w-full">
<MultiSelectValue placeholder="Choose channels" />
</MultiSelectTrigger>
<MultiSelectContent>
<MultiSelectList>
{(channel: string) => (
<MultiSelectItem key={channel} value={channel}>
{channel}
</MultiSelectItem>
)}
</MultiSelectList>
</MultiSelectContent>
</MultiSelect>
</div>
)
}Fluid
fluid makes the field as wide as its container.
import { Label } from "@booleanpress/ui/label"
import {
MultiSelect,
MultiSelectContent,
MultiSelectItem,
MultiSelectList,
MultiSelectTrigger,
MultiSelectValue,
} from "@booleanpress/ui/multi-select"
const ROLES = ["Administrator", "Editor", "Author", "Contributor", "Shop manager", "Customer"]
export default function MultiSelectFluid() {
return (
<div className="flex w-full flex-col gap-2">
<Label htmlFor="multi-select-roles">Roles that may see delivery logs</Label>
<MultiSelect items={ROLES} defaultValue={["Administrator", "Shop manager"]}>
<MultiSelectTrigger id="multi-select-roles" fluid>
<MultiSelectValue placeholder="Choose roles" />
</MultiSelectTrigger>
<MultiSelectContent>
<MultiSelectList>
{(role: string) => (
<MultiSelectItem key={role} value={role}>
{role}
</MultiSelectItem>
)}
</MultiSelectList>
</MultiSelectContent>
</MultiSelect>
</div>
)
}Disabled
disabled on the root keeps the choice and does not open; a disabled option stays in the list and cannot be chosen.
import { Label } from "@booleanpress/ui/label"
import {
MultiSelect,
MultiSelectContent,
MultiSelectItem,
MultiSelectList,
MultiSelectTrigger,
MultiSelectValue,
} from "@booleanpress/ui/multi-select"
const CHANNELS = ["Email", "SMS", "Slack", "Webhook"]
export default function MultiSelectDisabled() {
return (
<div className="flex w-full max-w-56 flex-col gap-4">
<div className="flex flex-col gap-2">
<Label htmlFor="multi-select-disabled">Alert channels</Label>
<MultiSelect items={CHANNELS} defaultValue={["Email", "Slack"]} disabled>
<MultiSelectTrigger id="multi-select-disabled" className="w-full">
<MultiSelectValue placeholder="Choose channels" />
</MultiSelectTrigger>
<MultiSelectContent>
<MultiSelectList>
{(channel: string) => (
<MultiSelectItem key={channel} value={channel}>
{channel}
</MultiSelectItem>
)}
</MultiSelectList>
</MultiSelectContent>
</MultiSelect>
</div>
<div className="flex flex-col gap-2">
<Label htmlFor="multi-select-option-disabled">Alert channels on the free plan</Label>
<MultiSelect items={CHANNELS} defaultValue={["Email"]}>
<MultiSelectTrigger id="multi-select-option-disabled" className="w-full">
<MultiSelectValue placeholder="Choose channels" />
</MultiSelectTrigger>
<MultiSelectContent>
<MultiSelectList>
{(channel: string) => (
<MultiSelectItem key={channel} value={channel} disabled={channel === "SMS" || channel === "Webhook"}>
{channel}
</MultiSelectItem>
)}
</MultiSelectList>
</MultiSelectContent>
</MultiSelect>
</div>
</div>
)
}Invalid
aria-invalid on the trigger draws the error edge and placeholder; aria-describedby reads the message with the name.
import { Label } from "@booleanpress/ui/label"
import {
MultiSelect,
MultiSelectContent,
MultiSelectItem,
MultiSelectList,
MultiSelectTrigger,
MultiSelectValue,
} from "@booleanpress/ui/multi-select"
const EVENTS = ["Delivered", "Bounced", "Complained", "Opened", "Clicked"]
export default function MultiSelectInvalid() {
return (
<div className="flex w-full max-w-56 flex-col gap-2">
<Label htmlFor="multi-select-invalid">Webhook events</Label>
<MultiSelect items={EVENTS} required>
<MultiSelectTrigger id="multi-select-invalid" className="w-full" aria-invalid aria-describedby="multi-select-invalid-error">
<MultiSelectValue placeholder="Choose events" />
</MultiSelectTrigger>
<MultiSelectContent>
<MultiSelectList>
{(event: string) => (
<MultiSelectItem key={event} value={event}>
{event}
</MultiSelectItem>
)}
</MultiSelectList>
</MultiSelectContent>
</MultiSelect>
<p id="multi-select-invalid-error" className="text-xs text-destructive-strong">
Choose at least one event to send.
</p>
</div>
)
}In a dialog
Inside the library's Dialog the list renders in the dialog, within its focus trap: clicks toggle options and Escape closes the list first.
import { useState } from "react"
import { Button } from "@booleanpress/ui/button"
import {
Dialog,
DialogBody,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@booleanpress/ui/dialog"
import { Label } from "@booleanpress/ui/label"
import {
MultiSelect,
MultiSelectContent,
MultiSelectItem,
MultiSelectList,
MultiSelectTrigger,
MultiSelectValue,
} from "@booleanpress/ui/multi-select"
const EVENTS = ["Delivered", "Bounced", "Complained", "Opened", "Clicked", "Unsubscribed", "Deferred", "Failed"]
export default function MultiSelectInDialog() {
const [events, setEvents] = useState(["Bounced", "Complained"])
return (
<Dialog>
<DialogTrigger asChild>
<Button variant="outline">Edit the webhook</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Edit the webhook</DialogTitle>
<DialogDescription>Choose the events this endpoint receives.</DialogDescription>
</DialogHeader>
<DialogBody className="flex flex-col gap-2">
<Label htmlFor="multi-select-webhook">Events</Label>
<MultiSelect items={EVENTS} value={events} onValueChange={setEvents}>
<MultiSelectTrigger id="multi-select-webhook" fluid>
<MultiSelectValue display="chips" placeholder="Choose events" />
</MultiSelectTrigger>
<MultiSelectContent>
<MultiSelectList>
{(event: string) => (
<MultiSelectItem key={event} value={event}>
{event}
</MultiSelectItem>
)}
</MultiSelectList>
</MultiSelectContent>
</MultiSelect>
</DialogBody>
<DialogFooter>
<DialogClose asChild>
<Button variant="outline">Cancel</Button>
</DialogClose>
<DialogClose asChild>
<Button disabled={events.length === 0}>Save</Button>
</DialogClose>
</DialogFooter>
</DialogContent>
</Dialog>
)
}Accessibility
- Semantics
- The trigger is a
buttonwithrole="combobox",aria-haspopup="dialog"andaria-expanded. The open list is a dialog named after the field's label, holding the filter input (a combobox witharia-activedescendant) and arole="listbox"witharia-multiselectable="true", whose chosen options havearia-selected="true". - Labels
- Name the trigger with a
LabelwhosehtmlForis itsid, oraria-label; the list takes the same name. The filter input is "Filter options", the select-all checkbox "Select all", the clear button "Clear", all from the provider. - Focus
- The trigger is one tab stop. Opening moves focus to the filter input in the list, where the arrow keys move the highlight; closing returns focus to the trigger. The select-all checkbox is reached with Shift+Tab from the filter.
- Known limits
- A chip's ร is a pointer shortcut and not in the tab order; with the keyboard, unpick the option in the list or press Backspace on the closed field to remove the last one. Its 22 px circle takes presses over a 24 px square, the minimum target of WCAG 2.5.8.
- Inside a dialog or sheet the list is clipped by the overlay's box and flips above the field when there is more room there.
- Select all chooses the options the filter leaves, not those hidden by it.
Keyboard
| Key | Behaviour |
|---|---|
| Enterorโ | On the trigger, opens the list with focus in its filter. |
| โorโ | In the list, highlight the next or the previous option. |
| Enter | In the list, chooses or unpicks the highlighted option; the list stays open. |
| Space | In the list, with nothing typed, chooses or unpicks the highlighted option. |
| AโZ | In the list, typing filters the options and shows the filter field. |
| Escape | Closes the list and returns focus to the trigger; inside a dialog, the dialog stays open. |
| Backspace | On the closed trigger, removes the last chosen option. |
| Tab | With clearable and options chosen, moves from the trigger to the clear button. |
API
MultiSelect
| Prop | Type | Default | Description |
|---|---|---|---|
actionsRef | RefObject<Actions | null> | A ref to imperative actions.
- unmount: Manually unmounts the combobox.
Call this after any externally controlled closing animation finishes. | |
autoComplete | string | Provides a hint to the browser for autofill. | |
autoHighlight | boolean | false | Whether the first matching item is highlighted automatically while filtering. |
defaultInputValue | string | number | readonly string[] | The uncontrolled input value when initially rendered.
To render a controlled input, use the inputValue prop instead. | |
defaultOpen | boolean | false | Whether the popup is initially open.
To render a controlled popup, use the open prop instead. |
defaultValue | Value[] | The values it starts with, when it controls itself. | |
disabled | boolean | false | Whether the component should ignore user interaction. |
filter | ((item: Item, query: string, itemToString?: ((item: Item) => string)) => boolean) | null | Filter function used to match items vs input query.
Receives the source item, which is the derived value's item when items is a createItems()
collection, and the item itself otherwise. | |
filteredItems | readonly Item[] | readonly Group<Item>[] | Filtered items to display in the list.
When provided, the list uses these items instead of filtering the items prop internally.
When items is also provided, this array must preserve its flat or grouped structure.
With a createItems() collection, pass source items rather than derived values.
Nullish entries are not supported, as in items.
Use when you want to control filtering logic externally with the useFilter() hook. | |
form | string | Identifies the form that owns the internal input. Useful when the combobox is rendered outside the form. | |
grid | boolean | false | Whether list items are presented in a grid layout. When enabled, arrow keys navigate across rows and columns inferred from DOM rows. |
highlightItemOnHover | boolean | true | Whether moving the pointer over items should highlight them.
Disabling this prop allows CSS :hover to be differentiated from the :focus (data-highlighted) state. |
id | string | The id of the component. | |
inputRef | Ref<HTMLInputElement> | A ref to the hidden input element. | |
inputValue | string | number | readonly string[] | The input value of the combobox. Use when controlled. | |
isItemEqualToValue | ((itemValue: Value, value: Value) => boolean) | Custom comparison logic used to determine if a combobox item value matches the current selected value. Useful when item values are objects without matching referentially.
With a createItems() collection, both arguments are derived values.
Defaults to Object.is comparison. | |
items | readonly unknown[] | The options: a flat array, or groups of { value, items }. Objects shaped { value, label } show their label. | |
itemToStringLabel | ((itemValue: Value) => string) | When the item values are objects (<Combobox.Item value={object}>), this function converts the object value to a string representation for display in the input.
If the shape of the object is { value, label }, the label will be used automatically without needing to specify this prop.
With a createItems() collection, this receives the derived value, and the collection's
getLabel takes precedence for values it can resolve. | |
itemToStringValue | ((itemValue: Value) => string) | When the item values are objects (<Combobox.Item value={object}>), this function converts the object value to a string representation for form submission.
If the shape of the object is { value, label }, the value will be used automatically without needing to specify this prop.
With a createItems() collection, this receives the derived value. | |
limit | number | -1 | The maximum number of items to display in the list. |
locale | LocalesArgument | The locale to use for string comparison. Defaults to the user's runtime locale. | |
loopFocus | boolean | true | Whether to loop keyboard focus back to the input when the end of the list is reached while using the arrow keys. The first item can then be reached by pressing <kbd>ArrowDown</kbd> again from the input, or the last item can be reached by pressing <kbd>ArrowUp</kbd> from the input. The input is always included in the focus loop per ARIA Authoring Practices. When disabled, focus does not move when on the last element and the user presses <kbd>ArrowDown</kbd>, or when on the first element and the user presses <kbd>ArrowUp</kbd>. |
modal | boolean | false | Determines if the popup enters a modal state when open.
- true: user interaction is limited to the popup: document page scroll is locked and pointer interactions on outside elements are disabled.
- false: user interaction with the rest of the document is allowed.
On touch devices, a true modal blocks outside taps but leaves the page scrollable unless the popup spans nearly the full viewport width, matching native iOS behavior. |
name | string | Identifies the field when a form is submitted. | |
onInputValueChange | ((inputValue: string, eventDetails: ChangeEventDetails) => void) | Event handler called when the input value changes. | |
onItemHighlighted | ((highlightedValue: Value, eventDetails: HighlightEventDetails) => void) | Callback fired when an item is highlighted or unhighlighted.
Receives the highlighted item value (or undefined if no item is highlighted) and event details with a reason property describing why the highlight changed.
The reason can be:
- 'keyboard': the highlight changed due to keyboard navigation.
- 'pointer': the highlight changed due to pointer hovering.
- 'none': the highlight changed programmatically. | |
onOpenChange | ((open: boolean, eventDetails: ChangeEventDetails) => void) | Event handler called when the popup is opened or closed. | |
onOpenChangeComplete | ((open: boolean) => void) | Event handler called after any animations complete when the popup is opened or closed. | |
onValueChange | ((value: Value[]) => void) | Called with the new values when an option is chosen or removed, the field is cleared or all are selected. | |
open | boolean | Whether the popup is currently open. Use when controlled. | |
openOnInputClick | boolean | true | Whether the popup opens when clicking the input. |
readOnly | boolean | false | Whether the user should be unable to choose a different option from the popup. |
required | boolean | false | Whether the user must choose a value before submitting a form. |
value | Value[] | The chosen values, when you control them. Pair it with onValueChange. | |
virtualized | boolean | false | Whether the items are being externally virtualized. |
MultiSelectCollection
MultiSelectContent
| Prop | Type | Default | Description |
|---|---|---|---|
align | "center" | "start" | "end" | start | How to align the popup relative to the specified side. |
alignOffset | number | OffsetFunction | 0 | Additional offset along the alignment axis in pixels.
Also accepts a function that returns the offset to read the dimensions of the anchor
and positioner elements, along with its side and alignment.
The function takes a data object parameter with the following properties:
- data.anchor: the dimensions of the anchor element with properties width and height.
- data.positioner: the dimensions of the positioner element with properties width and height.
- data.side: which side of the anchor element the positioner is aligned against.
- data.align: how the positioner is aligned relative to the specified side. |
anchor | Element | VirtualElement | RefObject<Element | null> | (() => Element | VirtualElement | null) | null | An element to position the popup against. By default, the popup will be positioned against the trigger. | |
className | string | ||
container | HTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null> | null | A parent element to render the portal element into. | |
filter | boolean | false | Shows the filter field at the top of the list. Without it, typing still filters, and the field shows once used. |
filterPlaceholder | string | The filter field's placeholder. | |
finalFocus | boolean | RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | void | HTMLElement | null) | Determines the element to focus when the popup is closed.
- false: Do not move focus.
- true: Move focus based on the default behavior (trigger or previously focused element).
- RefObject: Move focus to the ref element.
- function: Called with the interaction type (mouse, touch, pen, or keyboard).
Return an element to focus, true to use the default behavior, or false/undefined to do nothing. | |
initialFocus | boolean | RefObject<HTMLElement | null> | ((openType: InteractionType) => boolean | void | HTMLElement | null) | Determines the element to focus when the popup is opened.
- false: Do not move focus.
- true: Move focus based on the default behavior (first tabbable element or popup).
- RefObject: Move focus to the ref element.
- function: Called with the interaction type (mouse, touch, pen, or keyboard).
Return an element to focus, true to use the default behavior, or false/undefined to do nothing. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, ComboboxPopupState> | Allows you to replace the component's HTML element
with a different tag, or compose it with another component.
Accepts a ReactElement or a function that returns the element to render. | |
selectAll | boolean | false | Shows a checkbox at the top that chooses, or clears, every option the filter leaves. |
side | "top" | "bottom" | "left" | "right" | "inline-end" | "inline-start" | bottom | Which side of the anchor element to align the popup against. May automatically change to avoid collisions. |
sideOffset | number | OffsetFunction | 2 | Distance between the anchor and the popup in pixels.
Also accepts a function that returns the distance to read the dimensions of the anchor
and positioner elements, along with its side and alignment.
The function takes a data object parameter with the following properties:
- data.anchor: the dimensions of the anchor element with properties width and height.
- data.positioner: the dimensions of the positioner element with properties width and height.
- data.side: which side of the anchor element the positioner is aligned against.
- data.align: how the positioner is aligned relative to the specified side. |
style | CSSProperties | ((state: ComboboxPopupState) => CSSProperties) | Style applied to the element, or a function that returns a style object based on the component's state. |
MultiSelectEmpty
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | ||
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, ComboboxEmptyState> | Allows you to replace the component's HTML element
with a different tag, or compose it with another component.
Accepts a ReactElement or a function that returns the element to render. | |
style | CSSProperties | ((state: ComboboxEmptyState) => CSSProperties) | Style applied to the element, or a function that returns a style object based on the component's state. |
MultiSelectGroup
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | ||
items | readonly any[] | Items to be rendered within this group.
When provided, child Collection components will use these items. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, ComboboxGroupState> | Allows you to replace the component's HTML element
with a different tag, or compose it with another component.
Accepts a ReactElement or a function that returns the element to render. | |
style | CSSProperties | ((state: ComboboxGroupState) => CSSProperties) | Style applied to the element, or a function that returns a style object based on the component's state. |
MultiSelectItem
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | ||
description | ReactNode | A second, muted line under the label. | |
disabled | boolean | false | Whether the component should ignore user interaction. |
icon | ReactNode | Leading media beside both lines, such as an avatar or a flag. | |
index | number | The index of the item in the list. Improves performance when specified by avoiding the need to calculate the index automatically from the DOM. | |
indicator | "checkbox" | "check" | check | check marks a chosen option with a check at the start; checkbox draws a checkbox there. |
nativeButton | boolean | true | Whether the component renders a native <button> element when replacing it
via the render prop.
Set to false if the rendered element is not a button (for example, <div>). |
onClick | ((event: BaseUIEvent<MouseEvent<HTMLDivElement, MouseEvent>>) => void) | An optional click handler for the item when selected.
It fires when clicking the item with the pointer, as well as when pressing Enter with the keyboard if the item is highlighted when the Input or List element has focus. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, ComboboxItemState> | Allows you to replace the component's HTML element
with a different tag, or compose it with another component.
Accepts a ReactElement or a function that returns the element to render. | |
style | CSSProperties | ((state: ComboboxItemState) => CSSProperties) | Style applied to the element, or a function that returns a style object based on the component's state. | |
value | any | null | A unique value that identifies this item. |
MultiSelectLabel
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | ||
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, ComboboxGroupLabelState> | Allows you to replace the component's HTML element
with a different tag, or compose it with another component.
Accepts a ReactElement or a function that returns the element to render. | |
style | CSSProperties | ((state: ComboboxGroupLabelState) => CSSProperties) | Style applied to the element, or a function that returns a style object based on the component's state. |
MultiSelectList
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | ||
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, ComboboxListState> | Allows you to replace the component's HTML element
with a different tag, or compose it with another component.
Accepts a ReactElement or a function that returns the element to render. | |
style | CSSProperties | ((state: ComboboxListState) => CSSProperties) | Style applied to the element, or a function that returns a style object based on the component's state. |
MultiSelectSeparator
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | ||
orientation | "horizontal" | "vertical" | 'horizontal' | The orientation of the separator. |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, ComboboxSeparatorState> | Allows you to replace the component's HTML element
with a different tag, or compose it with another component.
Accepts a ReactElement or a function that returns the element to render. | |
style | CSSProperties | ((state: ComboboxSeparatorState) => CSSProperties) | Style applied to the element, or a function that returns a style object based on the component's state. |
MultiSelectTrigger
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | ||
clearable | boolean | false | Shows a clear button inside the field while options are chosen; it empties the selection. |
disabled | boolean | false | Whether the component should ignore user interaction. |
fluid | boolean | false | Fills the width of its container. |
nativeButton | boolean | true | Whether the component renders a native <button> element when replacing it
via the render prop.
Set to false if the rendered element is not a button (for example, <div>). |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, ComboboxTriggerState> | Allows you to replace the component's HTML element
with a different tag, or compose it with another component.
Accepts a ReactElement or a function that returns the element to render. | |
size | "default" | "sm" | "lg" | 28, 35 or 42 px tall while it holds one row. Defaults to the provider's controlSize. | |
style | CSSProperties | ((state: ComboboxTriggerState) => CSSProperties) | Style applied to the element, or a function that returns a style object based on the component's state. | |
variant | "default" | "filled" | filled fills the field grey. Defaults to the provider's fieldVariant. |
MultiSelectValue
Renders a span and passes it every other prop.
| Prop | Type | Default | Description |
|---|---|---|---|
display | "count" | "labels" | "chips" | labels | labels joins the chosen labels with commas; chips shows each as a removable chip; count says "3 selected". |
maxShown | number | Shows this many labels or chips, then "+{count} more". | |
placeholder | ReactNode | Shown, in the muted colour, while nothing is chosen. |
Every part takes className, merged with its defaults by cn(), and ref, which reaches the element it renders.
Data attributes: data-slot="multi-select-portal-marker" (MultiSelectContent), data-slot="multi-select-empty" (MultiSelectEmpty), data-slot="multi-select-group" (MultiSelectGroup), data-slot="multi-select-item" (MultiSelectItem), data-slot="multi-select-label" (MultiSelectLabel), data-slot="multi-select-list" (MultiSelectList), data-slot="multi-select-separator" (MultiSelectSeparator), data-slot="multi-select-trigger" (MultiSelectTrigger), data-slot="multi-select-value" (MultiSelectValue), and data-size, data-variant, data-indicator.
Provider strings: clear, selectedCount, moreSelected, removeItem, toggleOptions, filterOptions, selectAll (BooleanUIProvider's strings).
Theming
The trigger takes Select's tokens: --field (--field-filled filled), --control for the edge, --ring on focus and while open, --invalid when invalid. Chips use --secondary (--secondary-hover under the ร). The list uses --popover, --accent for the highlighted option and --highlight for chosen ones (--highlight-focus while highlighted); a drawn checkbox is --primary once chosen. Its motion is set once in theme.css.
The tokens its classes read. Change their values in your theme, and it follows.
| Token | Used for |
|---|---|
--accent | background |
--accent-foreground | text |
--control | border |
--control-hover | border, text |
--destructive-strong | text |
--field | background |
--field-disabled | background |
--field-disabled-foreground | text |
--field-filled | background |
--foreground | text |
--highlight | background |
--highlight-focus | background |
--highlight-foreground | text, border |
--invalid | border |
--muted-foreground | text |
--primary | border, background |
--primary-foreground | text |
--ring | border, outline |
--secondary | background |
--secondary-hover | background |