ui-kit0.0

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, Tab or 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. maxTags and validate refuse the same way, and onTagRejected tells you.
  • Backspace on 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

PropTypeDefaultDescription
value / defaultValuestring[][]Controlled / initial tags.
onValueChange(tags: string[]) => void—Called when a tag is added or removed.
maxTagsnumber—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'.
suggestionsstring[]—Shows a floating suggestion list.
delimitersstring[][',']Characters that end a tag when typed.
allowDuplicates / caseSensitivebooleanfalseDuplicate handling. "React" and "react" match by default.
addOnBlurbooleantrueTurn leftover text into a tag on blur.
name / separatorstring'' / ','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}".
groupClassNamestring—Class for the box; className goes on the text input.
...propsInputHTMLAttributes—Forwarded to the text input (placeholder, disabled, readOnly, inputMode, aria-*), including ref.

Keyboard

KeyAction
Enter / Tab / commaAdds the typed text (or the highlighted suggestion).
BackspaceOn empty text: highlights the last chip, then removes it.
Down / UpOpens the suggestions and moves the highlight.
EscapeCloses 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.