Skip to content
Hazine

Free Text Tag Input

Field where Enter, comma or Tab turns typed text into a removable chip inside the same bordered box. Duplicates are rejected with a brief highlight and pasted lists split into chips.

How it differs. Unconstrained chip entry in one wrapping box with delimiter keys, duplicate rejection and a two step Backspace, with no per-tag validation and no suggestion popup.

Install

pnpm dlx shadcn@latest add @hazine/tag-input-free-text

Adds 1 file, 1 Hazine item (@hazine/use-controllable-state), and 1 package (lucide-react).

First time? Add the registry to components.json
{
  "registries": {
    "@hazine": "https://api.hazine.dev/r/{name}.json"
  }
}

Needed once per project. Items resolve each other through the @hazine namespace.

Props10

value
string[]
defaultValue
string[] = []
onValueChange
(value: string[]) => void
max
number
Most tags the field accepts. Further entries are rejected and announced.
hint
string = "Enter, comma or Tab adds a tag"
Line under the field that names the keys. Hidden when disabled or read-only.
listLabel
string = "Tags"
Accessible name of the list of tags.
removeLabel
string = "Remove"
Start of each remove button name. The tag is appended: "Remove soil health".
formatCount
(count: number, max: number | undefined) => string
Text at the end of the line under the field, for example "4 of 8 tags".
formatAnnouncement
(announcement: TagAnnouncement) => string = describeAnnouncement
locale
string = "en-US"
Used to compare tags without regard to case and to format the count.

Also accepts every prop of Omit<React.ComponentProps<"input">, "type" | "value" | "defaultValue">.

Accessibility

Pattern
Form with labelled fields, Button (APG, opens in a new tab)
Keyboard
Keyboard support for Free Text Tag Input
KeyEffect
TabFocuses the text input. With text typed it adds the tag and stays in the field. With no text, or when the entry is rejected, it moves on
EnterAdds the typed text as a tag. With no text it is left to the surrounding form
CommaAdds the text before it as a tag
Backspace in the empty inputSelects the last tag, and a second press removes it. A held key stops at the empty input. Any other key or leaving the field clears the selection
Arrow Left at the start of the inputMoves focus to the remove button of the last tag (Arrow Right in right to left layouts)
Arrow Left, Arrow Right on a tagMoves between tags. Moving past the last tag returns to the input. The two keys swap in right to left layouts
Home, End on a tagMoves to the first tag or back to the input
Enter, Space, Backspace or Delete on a tagRemoves the tag and moves focus to the tag that takes its place, or to the input when none is left
Escape on a tagReturns focus to the input
A letter or digit on a tagReturns focus to the input and types the character there
PasteText with commas, tabs or line breaks is split into tags at the caret. Duplicates and entries over the limit are skipped and counted. When nothing is added the typed text stays
Screen reader

A native text input the consumer labels, after a labelled list of tags that each hold a remove button named after the tag. The field is one tab stop, arrow keys reach the tags, and every addition, removal, duplicate and limit is announced in a polite status region.

  • Announces: {tag} added.
  • Announces: {count} tags added.
  • Announces: {count} tags added. {skipped} skipped as duplicate or over the limit.
  • Announces: {tag} removed.
  • Announces: {tag} selected. Press Backspace again to remove it.
  • Announces: {tag} is already added.
  • Announces: Limit of {max} reached. Remove a tag to add another.
Reduced motion
No motion. Colour transitions only. The duplicate highlight is a steady inverted fill for 1.5 seconds.
Checked
Not checked yet. Automated results appear here once CI has run.

Dependencies2

  • @hazine/use-controllable-state
  • lucide-react

Filled chips are registry items the CLI adds for you. Outlined chips are npm packages.

Tokens shipped0

None. The item is styled by the tokens your theme already has.

More in Text Inputs