Tag Input

Chips-and-input tags field — Enter/comma commits, Backspace removes, duplicates and caps guarded.

TagInput turns free text into a normalized string list: Enter or a delimiter commits, Backspace on an empty input removes the last chip, and each chip carries its own remove button.

Installation

import { TagInput } from "@iammikz/srui";

Usage

reacttypescript

Invalid

TagInput is controlled (value: string[]), so MDX can't demo it statically — the markup is the same Usage wiring plus invalid:

const [tags, setTags] = useState(["react"]);

<TagInput value={tags} onChange={setTags} invalid placeholder="Add tag…" />

Props

PropTypeDefaultDescription
valuestring[]—The tags, in order
onChange(tags: string[]) => void—Full list after every add/remove
allowDuplicatesbooleanfalseAllow repeated tags
maxTagsnumber—Hard cap on count
delimitersstring[][","]Extra commit characters (Enter always commits)
addOnBlurbooleantrueCommit pending text on blur
validate(tag: string) => boolean—Per-tag gate
size"sm" | "md""sm"Chip size
invalidbooleanfalseDestructive border + aria-invalid on the input
disabled / placeholder——Usual field props

Accessibility

The wrapper is a labelled click target focusing the input; chip remove buttons announce Remove {tag}; Backspace undo works from the keyboard without ever needing the mouse.

Upgrades over the PRUI original: addOnBlur, maxTags, validate, and size presets.