Forms
Tag input
Type and press Enter to add tags.
Usage
A field that turns text into removable chips. It looks like our Input and grows taller as chips wrap. The value is a string array.
ada@northwind.comgrace@northwind.com
Press Enter, comma or Tab to add. Paste a list to add several. 2 of 5 added.
When to use
- Free-form lists of short values: recipients, keywords, labels, domains.
- Add a validate function when only some text is acceptable (emails, slugs).
Not for: choosing from a fixed set (use a select or a combobox), or values with long text (use a textarea).
Adding and removing
Enter,Tabor a comma adds the text. Leaving the field adds it too (addOnBlur).- Pasting splits on commas and new lines, so a whole list becomes chips at once.
- A duplicate is refused: the existing chip shakes and a screen reader hears why.
maxTagsandvalidaterefuse the same way, andonTagRejectedtells you. Backspaceon empty text highlights the last chip; a second press removes it. The × on a chip removes that one.
Suggestions
Pass suggestions for a floating list. It filters as you type, hides tags already added, and follows the combobox pattern: arrows move the highlight, Enter picks, Escape closes.
ReactTypeScript
Start typing, or press the down arrow to browse suggestions.
API
TagInput
| Prop | Type | Default | Description |
|---|---|---|---|
| value / defaultValue | string[] | [] | Controlled / initial tags. |
| onValueChange | (tags: string[]) => void | — | Called when a tag is added or removed. |
| maxTags | number | — | Most tags allowed. |
| validate | (tag, tags) => boolean | string | — | Return true to accept; false or a message to reject. |
| onTagRejected | (tag, reason, message?) => void | — | reason is 'duplicate', 'max' or 'invalid'. |
| suggestions | string[] | — | Shows a floating suggestion list. |
| delimiters | string[] | [','] | Characters that end a tag when typed. |
| allowDuplicates / caseSensitive | boolean | false | Duplicate handling. "React" and "react" match by default. |
| addOnBlur | boolean | true | Turn leftover text into a tag on blur. |
| name / separator | string | '' / ',' | Hidden input that submits the tags joined by separator. |
| size | 'sm' | 'md' | 'lg' | 'md' | Minimum height 32 / 36 / 44px. |
| removeLabel | (tag: string) => string | — | Accessible name of a chip × button. Default "Remove {tag}". |
| groupClassName | string | — | Class for the box; className goes on the text input. |
| ...props | InputHTMLAttributes | — | Forwarded to the text input (placeholder, disabled, readOnly, inputMode, aria-*), including ref. |
Keyboard
| Key | Action |
|---|---|
| Enter / Tab / comma | Adds the typed text (or the highlighted suggestion). |
| Backspace | On empty text: highlights the last chip, then removes it. |
| Down / Up | Opens the suggestions and moves the highlight. |
| Escape | Closes the suggestions. |
Accessibility
- A native text input inside the box; clicking anywhere in the box focuses it.
- Each chip × has a name that says what it removes. Added, removed and refused tags are announced in a polite live region.
- With suggestions the input is a combobox: aria-expanded, aria-controls, aria-activedescendant and a listbox of options.
- Inside a Field the id, aria-describedby, aria-invalid, required and disabled state are wired automatically.
Motion
- A new chip pops in (rise, scale .96, light blur); the suggestion list uses the same entrance and a faster exit.
- A refused duplicate shakes the existing chip for 360ms. Reduced motion keeps the live-region message and drops the shake.