Forms
TagInput
Free15.2 KB gzippedA text field that turns entries into removable tags (chips). Type and press Enter (or a delimiter such as a comma) to add; paste "a, b, c" to add several at once.
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Enter, Backspace, Arrow Left and 4 more · Full report
Import
import { TagInput } from "@vjdesigns/vjdesigns-ui";
Importing only TagInput adds about 15.2 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Basic
Press Enter or type a comma to add a tag. Backspace in an empty field selects the last tag.
- react
- design-system
import { useState } from "react";
import { Field, TagInput } from "@vjdesigns/vjdesigns-ui";
export function Basic() {
const [tags, setTags] = useState(["react", "design-system"]);
return (
<div style={{ width: "100%", maxWidth: "26rem" }}>
<Field label="Topics">
<TagInput value={tags} onValueChange={setTags} placeholder="Add a topic" chipTone="primary" />
</Field>
</div>
);
}
Emails
validate rejects bad entries with a message, transform cleans input, and maxTags caps the list.
Up to 5 email addresses.
import { Field, TagInput } from "@vjdesigns/vjdesigns-ui";
export function Emails() {
return (
<div style={{ width: "100%", maxWidth: "26rem" }}>
<Field label="Invite teammates" hint="Up to 5 email addresses.">
<TagInput
delimiters={[",", " "]}
addOnBlur
maxTags={5}
transform={(tag) => tag.trim().toLowerCase()}
validate={(tag) => /^\S+@\S+\.\S+$/.test(tag) || "Enter a valid email address."}
placeholder="name@company.com"
/>
</Field>
</div>
);
}
Accessibility
Keyboard instructions, generated from the delimiters you set, are linked to the input with aria-describedby. Each tag's remove button is named after the tag, and adding or removing a tag is announced.
- Accessibility
- React
Up to 5.
import { Field, TagInput } from "@vjdesigns/vjdesigns-ui";
export function Accessibility() {
return (
<div style={{ width: "100%", maxWidth: "26rem" }}>
<Field label="Skills" hint="Up to 5.">
<TagInput defaultValue={["Accessibility", "React"]} maxTags={5} placeholder="Add a skill" />
</Field>
</div>
);
}
Translated
The instructions, the remove buttons' names and the announcements come from the locale (German here).
- Barrierefreiheit
- Design
import { Field, TagInput, LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import de from "@vjdesigns/vjdesigns-ui/locales/de";
export function Translated() {
return (
<LocaleProvider locale="de" messages={de}>
<div style={{ width: "100%", maxWidth: "26rem" }}>
<Field label="Schlagwörter">
<TagInput defaultValue={["Barrierefreiheit", "Design"]} placeholder="Schlagwort hinzufügen" />
</Field>
</div>
</LocaleProvider>
);
}
Right to left
The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.
Basic
- react
- design-system
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
// Basic is the "Basic" example above.
<LocaleProvider locale="ar" messages={ar}>
<Basic />
</LocaleProvider>
Usage notes
Keyboard:
- Enter / delimiters (and Tab with
addOnTab): add the typed text. - Backspace in an empty input, or Left Arrow with the caret at the start: move focus to the last tag's remove button. A second Backspace (or Delete) removes that tag and focus returns to the next tag, or the input. This two-step pattern avoids deleting a tag by accident and lets screen readers announce which tag is about to be removed.
- On a tag: Left / Right Arrow move between tags and back to the input; Home / End jump to the first tag / the input; Backspace or Delete removes.
Inside a Field, the label, hint, error, required, disabled, read-only, and size are wired automatically. ref points at the <input>; native input props are spread onto it, while className and style go to the outer wrapper.
<Field label="Skills">
<TagInput defaultValue={["Defense"]} placeholder="Add a skill" />
</Field>
API reference
TagInput
| Prop | Type | Default |
|---|---|---|
valueThe tags (controlled). | string[] | — |
defaultValueInitial tags when uncontrolled. | string[] | [] |
onValueChangeCalled with the full array of tags after any add or remove. | (value: string[]) => void | — |
inputValueThe text being typed (controlled). | string | — |
defaultInputValueInitial text when uncontrolled. | string | "" |
onInputValueChangeCalled with the text in the input whenever it changes. | (inputValue: string) => void | — |
delimitersStrings that end a tag as they are typed, in addition to Enter. Pasted text is also split on them (and on line breaks). | string[] | [","] |
addOnTabTab adds the typed text as a tag (focus stays in the input). Tab still moves focus normally when the input is empty or the text is rejected, so it never traps the keyboard. | boolean | false |
addOnBlurAdd the typed text as a tag when the input loses focus. | boolean | false |
allowDuplicatesAllow the same tag more than once. When | boolean | false |
maxTagsMaximum number of tags. When reached, the input becomes read-only, the placeholder hides, and "Maximum of N tags reached" is announced and added to the input's description. | number | — |
validateChecks a tag before it is added (after trimming and | (tag: string) => boolean | string | — |
transformNormalizes a tag before validation and duplicate checks (e.g. | (tag: string) => string | — |
sizeField height, padding, and chip size. Inherits from a surrounding | "sm""md""lg" | "md" |
disabledDisables the input and every chip (no remove buttons). Inherits from a surrounding | boolean | false |
readOnlyShows the tags without remove buttons or a text input. Inherits from a surrounding | boolean | false |
invalidDanger border and | boolean | false |
requiredRequires at least one tag. Sets | boolean | false |
placeholderPlaceholder for the text input, shown only while there are no tags. | string | — |
nameForm field name. Renders one | string | — |
chipVariantChip variant for every tag. | "solid""soft""outline" | "soft" |
chipToneChip tone for every tag. | "neutral""primary""accent""success""warning""danger""info" | "neutral" |
removeLabelAccessible name of each tag's remove button. | (tag: string) => string | (tag) => `Remove ${tag}` |
tagListLabelAccessible name of the tag list. Defaults to the surrounding | string | — |
instructionsVisually hidden keyboard instructions, linked to the input with | string | — |
messagesOverride announcement and fallback text (for localization). | Partial<TagInputMessages> | — |
inputClassNameClass name for the | string | — |
refRef to the text | Ref<HTMLInputElement> | — |
Also accepts native <input> attributes, plus className, style and ref.
See what changed in each version in the Changelog.
Accessibility report
TagInput targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10037 passed · 0 failed · 28 not applicable · 10 to check by hand
Dark mode
Score 10037 passed · 0 failed · 28 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
| Key | Action |
|---|---|
| Enter | Adds the typed text as a tag (also a delimiter, and Tab with addOnTab). |
| Backspace | In an empty field: focuses the last tag. On a tag: removes it. |
| Arrow Left | With the caret at the start: focuses the last tag. |
| Arrow LeftArrow Right | On a tag: moves between tags and back to the field. |
| HomeEnd | On a tag: first tag, or the field. |
| Delete | On a tag: removes it; focus moves to the next tag or the field. |
Roles and states
| Element | Role | States and properties |
|---|---|---|
| Tags | list | aria-labelledby → label |
| Tag remove button | button | aria-label ("Remove …") |
<input> | textbox | aria-describedby, aria-invalid |
| Live region | status | Announces added and removed tags |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |