Tags
A labelled input field that turns free-form text entries into removable pill tags with a gliding pick ring, duplicate detection, and optional inline editing.
import { TagInput } from '@uthereal/ui/tag-input'Tag input playground
Overview
TagInput renders a labelled text field that turns typed entries into removable pill tags on Zag's tags-input machine. Pressing Enter, typing the delimiter, or moving focus out of the field commits the trimmed draft as a tag. Pressing Backspace or the arrow keys from the start of the input picks an existing tag with a gliding accent ring before removing it.
Your application owns the tags array and external validation. TagInput enforces maxTags, maxLength, and duplicate rules inline, reports every change through onValueChange, and never opens browser validation bubbles.
| Capability | Behavior |
|---|---|
| Entry & delimiter | Enter, typing delimiter (, by default), or blurring commits trimmed text; pasted text lands in the input as typed |
| Pick & removal | Backspace, arrow keys, or clicking picks a tag with a gliding ring; Backspace, Delete, or the remove button deletes |
| Limits & repeats | Caps tag count (maxTags, up to 50) and length (maxLength, up to 200); rejects case-insensitive repeats by default |
| Inline editing | Set editable to edit a tag via double-click or Enter when picked; Enter saves, Escape cancels, empty text deletes |
| Form submission | With name, a hidden input submits the comma-space-joined tag list with native HTML forms; form reset restores defaults |
Use TagInput for free-form keywords, labels, topics, or recipients. Use Text for single-line or multi-line prose, and use a select or multiselect when choices come from a fixed list.
Usage
'use client'
import { useState } from 'react'
import { TagInput } from '@uthereal/ui/tag-input'
export function KeywordTags() {
const [tags, setTags] = useState(['design', 'frontend'])
return (
<TagInput
label="Keywords"
name="keywords"
placeholder="Add a keyword"
description="Press Enter or comma to add a keyword."
value={tags}
onValueChange={setTags}
/>
)
}Omit value for an uncontrolled field initialized from defaultValue. When name is set, a hidden <input> submits the tags with the surrounding form unless the field is disabled.
Examples
Limits, duplicates, and custom delimiters
Set maxTags and maxLength to bound entries. By default (allowDuplicates={false}), repeating a tag ignoring case ("Design" for "design") keeps the typed draft in the input, pulses the existing tag, and announces duplicateLabel. Change delimiter to another punctuation or space character (such as ;) when tags themselves contain commas.
Inline editing and non-editable states
Set editable to let users double-click a tag or press Enter on a picked tag to edit it in place (Enter saves, Escape cancels, and saving an empty tag removes it). Set readOnly to keep tags focusable and submitted with a form without remove buttons, or set disabled to dim the control and remove it from the tab order.
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
label | stringDefault: "Tags" | Visible label and accessible name. Name the information asked for, in sentence case. |
hideLabel | booleanDefault: false | Hide the label visually when the context already names the field. It is still announced. |
description | string— | Supporting text below the field, announced with it. Use it for format hints and constraints. |
error | string— | Validation message from your application. Setting it marks the field invalid; the message is linked to the field and announced politely. |
required | booleanDefault: false | Marks the field as required for assistive technology and shows an indicator. Your application validates the value. |
readOnly | booleanDefault: false | The value can be focused, selected, and copied, but not edited. It is still submitted with a form. |
disabled | booleanDefault: false | Unavailable and removed from the tab order. A disabled field is not submitted with a form. |
name | string— | Native form field name, submitted with the value in a form. |
placeholder | stringDefault: "Add a tag" | Text shown while there are no tags; defaults to "Add a tag". It rises back in when the last tag is removed. Never a substitute for the label. |
defaultValue | string[]Default: [] | Initial tags, up to 50. Later argument edits do not reset an existing instance; use value and onValueChange to control it. |
maxTags | integerDefault: 50 | Most tags the user can add, up to 50. Further entries are ignored until a tag is removed. |
maxLength | integerDefault: 50 | Most characters in one tag, up to 200. |
delimiter | stringDefault: "," | Typing this character adds the tag, like Enter. One punctuation or space character. As in Arc, pasted text lands in the field as typed text. |
allowDuplicates | booleanDefault: false | Accept a tag that is already in the list. By default a repeat is rejected ignoring case ("Design" repeats "design"): the existing tag pulses, the typed text stays, and duplicateLabel is announced. |
editable | booleanDefault: false | Let the user edit a tag: pick it and press Enter, or double-click it. Enter saves, Escape cancels, and an emptied tag is removed. Off by default, as in Arc. |
removeLabel | stringDefault: "Remove {label}" | Accessible name of each remove button. {label} is replaced with the tag, e.g. "Remove {label}". |
duplicateLabel | stringDefault: "{label} is already added" | Announced politely when a repeated tag is rejected. {label} is replaced with the existing tag. |
addedLabel | stringDefault: "Added {label}" | Announced politely when a tag is added, as in Arc ("Added {label}"). {label} is replaced with the tag. |
removedLabel | stringDefault: "Removed {label}" | Announced politely when a tag is removed, as in Arc ("Removed {label}"). {label} is replaced with the tag. |
selectedLabel | stringDefault: "{label} selected. Press Backspace to remove it." | Announced politely when Backspace, an arrow key or a click picks a tag, as in Arc. {label} is replaced with the tag. |
variant | outline | soft | ghostDefault: "outline" | Field surface: outline for forms, soft on busy surfaces, ghost for inline editing without a border. |
size | sm | md | lgDefault: "md" | Field height and text size: 32, 36, or 46 pixels. Matches the button and dropdown trigger of the same size. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes use the same interaction behavior. |
theme | TagInputTheme— | Color mode, accent, and semantic tokens. See Theming for all keys and defaults. |
motion | none | subtle | expressiveDefault: "subtle" | Tags scale and blur in, glide aside and leave; the pick ring glides between tags; the shell height follows wrapped rows. Reduced motion keeps short fades; none makes every change immediate. |
dir | ltr | rtl— | Reading direction. Omit it to inherit the page direction. |
React integration
| Prop | Purpose |
|---|---|
value, onValueChange | Controlled string[] tag list. onValueChange fires on every add, edit, and removal in both modes |
ref | Ref to the native text <input> element. |
preset | Application defaults (such as delimiter and localized announcement templates), overridden locally. |
tokens | CSS custom properties (--ui-*) applied after the typed theme on the field root. |
renderIcon(name, context) | Custom remove icon renderer; context provides size and slot ('remove'). Keep it decorative. |
className, style | Applied to the root field element, which carries the resolved --ui-* tokens. |
| Native attributes | Forwarded to <input> (autoFocus, aria-*, data-*); keyboard and input events are managed. |
The pure case-insensitive comparator sameTag(a, b) and tagSchema are also exported from @uthereal/ui/tag-input.
Keyboard & accessibility
| Key | Interaction |
|---|---|
Tab | Moves between each tag's remove button and the text input. |
Enter, delimiter | Commits the typed draft as a tag. When editable is enabled, Enter on a picked tag edits it. |
Backspace | At the start of the input, picks the last tag; pressing again removes the picked tag. |
Delete | Removes the currently picked tag and returns focus to the input. |
ArrowLeft, ArrowRight | From the start of the input, picks and moves across tags in reading order; past the end returns. |
Escape | Clears the current pick without modifying text, or cancels an active inline tag edit. |
Enter (editing) | Saves the edited tag text; saving an empty value deletes the tag. |
The input is labelled by label (aria-labelledby) and described by description, error, and any consumer aria-describedby. required sets aria-required="true" while leaving validation to the host. Each tag's remove button is a native <button> tab stop named by removeLabel ("Remove {label}").
Additions, removals, picks, and rejected duplicates announce through a pre-mounted role="status" (aria-live="polite", aria-atomic="true") region using addedLabel, removedLabel, selectedLabel, and duplicateLabel. Each tag label sets unicode-bidi: plaintext so mixed-direction tags truncate cleanly. In dir="rtl", arrow navigation mirrors to reading order and the pick ring measures from the inline-start edge. forced-colors: active preserves tag borders, Highlight pick rings and edit edges, GrayText disabled tags, and Highlight focus outlines.
Motion and theming
- Tags and caret: new tags scale in from
90%through a soft blur (motionTokens.blur.soft) on the morph spring while existing tags and the input caret glide to their updated slots; removed tags shrink to90%and fade over120ms. - Shell height: a
ResizeObserveranimates the shell height on the smooth spring as tags wrap onto new rows or collapse back. - Pick ring: picking a tag springs the accent ring in (
snappy) and glides it between tags on the morph spring; clearing the pick fades and scales it out over120ms. - Feedback: rejected duplicates pulse the existing tag to
1.06(360ms), the placeholder rises back in when the last tag leaves, remove buttons press to96%over120msand release on Arc's CSS spring, and field messages exit words over120ms. - Reduced motion:
prefers-reduced-motion: reducedisables scale, blur, layout glide, height springs, duplicate pulses, and press scales while keeping120msopacity crossfades.motion="none"makes every update immediate (0ms).
theme accepts the core and control token groups, plus borderStrong (hover shell edge) and accentSubtle (pick-ring fill). The shell rests on border, steps to borderStrong on hover, and turns ink on focus. An optional UtherealProvider supplies application-wide defaults.
Composition
TagInput is a leaf component. Its tag list (string[]) is host state at /fields/instance-<id>/value, initialized from defaultValue. Stored tags survive configuration edits to labels, limits, or appearance. See Building with agents.
{
"type": "TagInput",
"props": {
"label": "Keywords",
"placeholder": "Add a keyword",
"defaultValue": ["design", "frontend"],
"maxTags": 10
},
"children": []
}