Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Forms

TagInput

Free15.2 KB gzipped

A 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

tsx
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
Press Enter or a comma to add a tag. Backspace or the left arrow moves to added tags.
tsx
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.

Press Enter, a comma, or a space to add a tag. Backspace or the left arrow moves to added tags.

Up to 5 email addresses.

tsx
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
Press Enter or a comma to add a tag. Backspace or the left arrow moves to added tags.

Up to 5.

tsx
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
Drücken Sie Eingabe oder ein Komma, um einen Tag hinzuzufügen. Mit der Rücktaste oder dem Pfeil nach links gelangen Sie zu den hinzugefügten Tags.
tsx
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
اضغط Enter أو فاصلة لإضافة وسم. ينقلك مفتاح المسافة للخلف أو السهم الأيمن إلى الوسوم المضافة.
tsx
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.

tsx
<Field label="Skills">
  <TagInput defaultValue={["Defense"]} placeholder="Add a skill" />
</Field>

API reference

TagInput

TagInput props
PropTypeDefault
value

The tags (controlled).

string[]—
defaultValue

Initial tags when uncontrolled.

string[][]
onValueChange

Called with the full array of tags after any add or remove.

(value: string[]) => void—
inputValue

The text being typed (controlled).

string—
defaultInputValue

Initial text when uncontrolled.

string""
onInputValueChange

Called with the text in the input whenever it changes.

(inputValue: string) => void—
delimiters

Strings that end a tag as they are typed, in addition to Enter. Pasted text is also split on them (and on line breaks).

string[][","]
addOnTab

Tab 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.

booleanfalse
addOnBlur

Add the typed text as a tag when the input loses focus.

booleanfalse
allowDuplicates

Allow the same tag more than once. When false, entering an existing tag highlights it briefly and announces "{tag} is already added". Comparison is exact after transform (use transform to lowercase for case-insensitive tags).

booleanfalse
maxTags

Maximum 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—
validate

Checks a tag before it is added (after trimming and transform). Return true to accept, false to reject with a generic message, or a string to reject with that message. The message is shown under the field, linked with aria-describedby, and announced; the rejected text stays in the input so it can be fixed.

(tag: string) => boolean | string—
transform

Normalizes a tag before validation and duplicate checks (e.g. (t) => t.toLowerCase()).

(tag: string) => string—
size

Field height, padding, and chip size. Inherits from a surrounding Field.

"sm""md""lg""md"
disabled

Disables the input and every chip (no remove buttons). Inherits from a surrounding Field.

booleanfalse
readOnly

Shows the tags without remove buttons or a text input. Inherits from a surrounding Field.

booleanfalse
invalid

Danger border and aria-invalid. Inherits from a surrounding Field.

booleanfalse
required

Requires at least one tag. Sets aria-required on the input and a native validation message (messages.required) while there are no tags, so form submission is blocked. Inherits from a surrounding Field.

booleanfalse
placeholder

Placeholder for the text input, shown only while there are no tags.

string—
name

Form field name. Renders one <input type="hidden" name={name}> per tag, so formData.getAll(name) returns the tags as an array.

string—
chipVariant

Chip variant for every tag.

"solid""soft""outline""soft"
chipTone

Chip tone for every tag.

"neutral""primary""accent""success""warning""danger""info""neutral"
removeLabel

Accessible name of each tag's remove button.

(tag: string) => string(tag) => `Remove ${tag}`
tagListLabel

Accessible name of the tag list. Defaults to the surrounding Field's label (or the input's aria-labelledby), else "Tags".

string—
instructions

Visually hidden keyboard instructions, linked to the input with aria-describedby. Generated from delimiters and addOnTab by default.

string—
messages

Override announcement and fallback text (for localization).

Partial<TagInputMessages>—
inputClassName

Class name for the <input> element. className goes to the outer wrapper.

string—
ref

Ref to the text <input> (null in read-only mode).

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)

Running accessibility audit

Checking the examples above…

Lighthouse audit

Light mode

Score 100

37 passed · 0 failed · 28 not applicable · 10 to check by hand

Dark mode

Score 100

37 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

Keyboard
KeyAction
EnterAdds the typed text as a tag (also a delimiter, and Tab with addOnTab).
BackspaceIn an empty field: focuses the last tag. On a tag: removes it.
Arrow LeftWith the caret at the start: focuses the last tag.
Arrow LeftArrow RightOn a tag: moves between tags and back to the field.
HomeEndOn a tag: first tag, or the field.
DeleteOn a tag: removes it; focus moves to the next tag or the field.

Roles and states

Roles and states
ElementRoleStates and properties
Tagslistaria-labelledby → label
Tag remove buttonbuttonaria-label ("Remove …")
<input>textboxaria-describedby, aria-invalid
Live regionstatusAnnounces added and removed tags

Manual checks

Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.

Manual accessibility checks
CheckWhat to testWCAG 2.2
KeyboardEvery 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)
FocusFocus 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 readersNames, 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)
ColorMeaning 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 reflowAt 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 targetsClick 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)
MotionAnimations respect the reduced-motion setting.2.3.3 (AAA)