Creatable multi-select
A text field where people type values and press Enter to turn each one into a badge, with optional suggestions.
Type a value and press Enter. Pasting several lines from a spreadsheet creates
one badge per cell.
When to use
- To collect a list of free values, such as process numbers, e-mails or keywords.
- To accept a paste of many values from a spreadsheet at once.
- When suggestions help but are not the only valid answer.
When not to use
- Choosing only from a closed list. Use the multiple selector.
- A single free value. Use an Input.
- Values that must be validated against the server before they appear. Build the check outside the field, because the component accepts any text.
Variants
| Variant | Use for |
|---|---|
default |
A compact field with a secondary border. |
form |
Forms. Primary border, rounded corners and a focus ring when the field is focused. |
0001234-56.2024.8.26.0100
States
Disabled
0001234-56.2024.8.26.0100
0007890-12.2023.8.26.0001
Examples
Suggestions
With options, a list opens under the field while typing. Matching an option
label exactly selects that option. Any other text becomes a new badge.
Narrow containers
constrainBadges truncates long labels and shows the full text in a tooltip.
Limit the number of values
maxSelected stops new badges and calls onMaxSelected. Tell the user why
nothing was added.
Content
- Placeholders explain the gesture: “Digite e pressione Enter”.
- Keep
splitOnWhitespaceon for identifiers without spaces, such as process numbers. Turn it off for labels that may contain spaces, such as “Revisão pendente”. - Use
onMaxSelectedto show a message in the page. The field gives no feedback by itself.
Accessibility
- The wrapper has
role="combobox"andaria-expanded, and the text input inside it receives the typing. PassinputProps={{ "aria-label": "…" }}so the input has a name. Entercreates a badge.BackspaceorDeleteon an empty input removes the last badge, except fixed ones.Escapecloses the suggestions.- The remove button of each badge can be reached with
Taband shows a focus ring. - Suggestions are plain buttons in a portal. They are not announced as a list box and arrow keys do not move through them.
Code
import { CreatableMultiSelect } from "@repo/ui/creatable-multi-select";
import type { CreatableOption } from "@repo/ui/creatable-multi-select";
const [value, setValue] = useState<CreatableOption[]>([]);
<CreatableMultiSelect
inputProps={{ "aria-label": "Números de processo" }}
onChange={setValue}
placeholder="Digite e pressione Enter"
value={value}
variant="form"
/>;
Props
CreatableMultiSelect| Prop | Type | Default | Description |
|---|---|---|---|
constrainBadges | boolean | false | Truncates long badge labels and shows the full text in a tooltip |
disabled | boolean | — | Blocks typing and removing badges |
hideClearAllButton | boolean | false | Hides the button that clears every badge |
hidePlaceholderWhenSelected | boolean | — | Hides the placeholder once there is at least one badge |
maxSelected | number | Number.MAX_SAFE_INTEGER | Maximum number of badges |
placeholder | string | "" | Hint shown in the input |
splitOnWhitespace | boolean | true | Splits typed or pasted text on spaces into several badges. When false, the whole text is one badge |
variant | "default" | "form" | default | Border and focus style of the field |
More props| Prop | Type | Default | Description |
|---|---|---|---|
value | CreatableOption[] | — | Selected options. The component keeps its own copy and calls onChange. |
onChange | (options: CreatableOption[]) => void | — | Called with the full list after every change. |
onInputChange | (value: string) => void | — | Called when the typed text changes. |
options | CreatableOption[] | [] | Suggestions shown while typing. |
onMaxSelected | (maxLimit: number) => void | — | Called when the user tries to exceed maxSelected. |
inputProps | InputHTMLAttributes<HTMLInputElement> | — | Props for the text input, such as aria-label and className. |
badgeClassName | string | — | Extra classes for the badges, for spacing only. |
CreatableOption| Prop | Type | Default | Description |
|---|---|---|---|
value | string | — | Unique identifier. |
label | string | — | Text shown in the badge. |
fixed | boolean | — | Keeps the badge in place, without a remove button. |
Known issues
| Issue | Effect |
|---|---|
The wrapper div has role="combobox", tabIndex={0} and aria-label="Multi-select input", and contains the real input and buttons. |
Screen readers find a combobox inside a combobox, and the fixed English name cannot be translated. |
| The remove button on each badge and the clear-all button have no accessible name. | Screen readers announce “button” with no purpose. |
| The clear-all button has no focus style and an icon-only 24px target. | Keyboard users cannot see where focus is. |
Suggestions use hover:bg-accent and have no role="option" or keyboard navigation. |
Users cannot choose a suggestion with arrow keys. It depends on a token from the old color system. |
Disabled uses opacity-70 on the whole field. |
Opacity lowers contrast instead of using disabled tokens. |
The default variant has no focus ring. |
Focus is only visible through the text caret. |
CreatableOption accepts [key: string]: any. |
Loses type safety on extra fields. |