Multiple selector
A searchable field that lets people pick several options from a list and shows the choices as removable badges.
Select the field, type to filter and press Enter to add an option. Select a
badge to remove it.
When to use
- To choose several values from a known list, such as document types, reviewers or labels.
- To filter a table by more than one value at once.
- When the list is long enough to need search.
When not to use
- Choosing a single value. Use a Combobox or a Select.
- Fewer than five options that fit on the page. Use checkboxes.
- Free text values with no list, such as process numbers. Use the creatable multi-select.
- A choice that depends on another one. Use the cascading multi-selector.
States
Collapsed badges
When more options are selected than collapseSelectedTo, the extra ones move
into a +N badge that opens the full list.
Disabled
Examples
Grouped options
Use groupBy with the name of an option field to group the list under
headings.
Search and create
onSearchSync filters options in memory. Use onSearch for a request to the
server, and creatable to let people add a value that is not in the list.
Limit the selection
maxSelected stops new selections and calls onMaxSelected. Tell the user why
nothing happened.
Fixed options
An option with fixed: true stays selected and has no remove button.
Content
- Name the field by what it holds: “Tipos de documento”, “Revisores”.
- Placeholders say what to do: “Selecione os tipos”, not “Digite aqui”.
- Pass
emptyIndicatorwith a short message, such as “Nenhum tipo encontrado.” - Option labels are short and distinct. Long labels are truncated and show a tooltip with the full text.
Accessibility
- The list is built on
cmdk: arrow keys move through the options,Enterselects, and typing filters. BackspaceorDeletein an empty input removes the last badge.Escapecloses the list.- The input has no visible label of its own. Pass an accessible name with
inputProps={{ "aria-label": "…" }}and keep a visible label next to the field. - Each badge is a button. Fixed and disabled badges set
aria-disabled. - Badges and the
+Nbutton show a focus ring withfocus-visible. - The list renders in a portal on
document.body. Inside a dialog, passdropdownContainerso the list stays inside the focus trap and scrolls.
Code
import { MultipleSelector } from "@repo/ui/multi-select";
import type { Option } from "@repo/ui/multi-select";
const [value, setValue] = useState<Option[]>([]);
<MultipleSelector
inputProps={{ "aria-label": "Tipos de documento" }}
onChange={setValue}
options={[
{ label: "Petição inicial", value: "peticao_inicial" },
{ label: "Contestação", value: "contestacao" },
]}
placeholder="Selecione os tipos"
value={value}
/>;
Props
MultipleSelector| Prop | Type | Default | Description |
|---|---|---|---|
collapseSelectedTo | number | 3 | Shows only the first N selected badges and a +N badge for the rest |
creatable | boolean | false | Lets people create an option when nothing matches |
disabled | boolean | false | Blocks typing and removing badges |
groupBy | string | — | Key of the option field used to group the list |
hideClearAllButton | boolean | false | Hides the button that clears the whole selection |
hidePlaceholderWhenSelected | boolean | true | Hides the placeholder once something is selected |
maxSelected | number | Number.MAX_SAFE_INTEGER | Maximum number of selected options |
placeholder | string | — | Hint shown in the input |
More props| Prop | Type | Default | Description |
|---|---|---|---|
value | Option[] | — | Selected options. The component keeps its own copy and calls onChange. |
options | Option[] | — | The options shown in the list, controlled by the caller. |
defaultOptions | Option[] | [] | Initial options when the list is built from search results. |
onChange | (options: Option[]) => void | — | Called with the full selection after every change. |
onSearch | (value: string) => Promise<Option[]> | — | Async search. Debounced by `delay` (500ms by default). |
onSearchSync | (value: string) => Option[] | — | Synchronous search. Never shows the loading indicator. |
triggerSearchOnFocus | boolean | false | Runs onSearch when the input receives focus, to load initial options. |
onMaxSelected | (maxLimit: number) => void | — | Called when the user tries to exceed maxSelected. |
emptyIndicator | ReactNode | — | Content shown when no option matches. |
loadingIndicator | ReactNode | "Carregando..." | Content shown while an async search runs. |
isLoading | boolean | — | Forces the loading state. |
clearAllLabel | string | "Limpar todos" | Label of the clear button inside the +N popover. |
showAllSelectedOnClick | boolean | true | Makes the +N badge open a popover with every selected option. |
dropdownContainer | HTMLElement | null | — | Portal target for the list. Use it inside dialogs and sheets. |
inputProps | CommandInput props | — | Props for the input, such as aria-label and onValueChange. |
badgeClassName | string | — | Extra classes for the badges, for spacing only. |
Option| Prop | Type | Default | Description |
|---|---|---|---|
value | string | — | Unique identifier. |
label | string | — | Text shown in the list and in the badge. |
disable | boolean | — | Shows the option but blocks selecting it. |
fixed | boolean | — | Keeps the option selected, without a remove button. |
[key: string] | string | boolean | undefined | — | Any extra field. Name one in groupBy to group options. |
Known issues
| Issue | Effect |
|---|---|
Disabled and fixed badges use opacity-60, and the badge × icons use opacity-50. |
Opacity lowers contrast of the text and icons. Disabled state should use disabled tokens. |
The clear-all button (aria-label="Limpar seleção") has no focus style, no hover background and a 24px hit area. |
Keyboard users cannot see when it has focus. It is at the minimum size. |
aria-label="Limpar seleção" and aria-label="Ver mais N selecionados" are hardcoded in Portuguese. |
Apps cannot translate them. Only clearAllLabel and loadingIndicator are props. |
| The field has no built-in accessible name. | Without inputProps["aria-label"] a screen reader announces an unnamed text field. |
The container forces !bg-primary with an important modifier. |
Callers cannot change the background with className. |
showAllSelectedOnHover is deprecated, and its name says hover. |
It only keeps the +N popover enabled and still opens on click. The name misleads call sites. |