Components

Tag Input

An accessible React tag input (chip input): type and press Enter or comma to add tags as chips, Backspace twice to remove, paste a comma-separated list to add many at once, with duplicate detection, validation, a max count, optional suggestions and form submission — animated with Motion and styled with Tailwind CSS.

  • Chips
  • Paste lists
  • Duplicate shake
  • Suggestions
  • Live announcements
  • Form-ready
reactmotiontailwind
Press Enter or comma to add a tag. Press Backspace twice in the empty field to remove the last tag.

Enter or comma to add · Backspace twice to remove · try a duplicate

Installation

$ npx shadcn@latest add https://duskui.com/r/tag-input.json

Usage

post-tags.tsx
"use client"

import * as React from "react"
import { TagInput } from "@/components/dusk/tag-input/tag-input"

export function PostTags() {
  const [tags, setTags] = React.useState<string[]>([])
  return <TagInput aria-label="Tags" value={tags} onValueChange={setTags} max={5} />
}

Examples

With suggestions

Pass suggestions and the field becomes a combobox: matches filter as you type (prefix matches first), Arrow keys move a gliding highlight and Enter picks. Tags already added are hidden from the list.

Next.js
Press Enter or comma to add a tag. Press Backspace twice in the empty field to remove the last tag.

Validation, limit & forms

transform normalizes each tag, validate can reject it with a message, and onReject lets you show that message in a FieldError. With max a counter appears; with name every tag is submitted. Paste ada@dusk.dev, grace@dusk.dev to add both.

Press Enter or comma to add a tag. Press Backspace twice in the empty field to remove the last tag. Up to 4 tags.

Paste a comma-separated list to add several at once.

API Reference

PropTypeDefaultDescription
value / onValueChangestring[] / (tags: string[]) => void—Controlled tags.
defaultValuestring[][]Uncontrolled initial tags.
maxnumber—Maximum number of tags. Shows an n/max counter.
suggestionsstring[]—Options shown in a filtered list while typing.
separatorsstring[][","]Characters that commit a tag besides Enter. Pastes also split on new lines and tabs.
allowDuplicatesbooleanfalseAllow the same tag twice (compared case-insensitively).
validate(tag, tags) => boolean | string—Return false or an error message to reject a tag.
transform(tag: string) => stringtrimNormalize a tag before it's checked.
onReject(tag, reason: "duplicate" | "invalid" | "max", message) => void—Fires when a tag is refused.
namestring—Submit each tag with its own hidden input.
placeholderstring"Add a tag…"Shown while there are no tags.
id / aria-label / aria-describedby / aria-invalidstring / boolean—Forwarded to the text input.

Accessibility

  • Every add, removal and rejection is announced through a polite live region, including the running count when there's a max.
  • Backspace in the empty field first highlights the last chip and announces it; a second press removes it, so tags are never deleted by accident.
  • Each chip has a labelled remove button (“Remove react”). Instructions are linked to the input with aria-describedby.
  • With suggestions, the input follows the combobox pattern: role="combobox", aria-expanded, aria-controls and aria-activedescendant.
  • An empty Enter still submits the surrounding form. Chips fade instead of popping under prefers-reduced-motion, and shakes are skipped.