Design System
Forms

Tags input

Free-form list entry: type a value, press Enter, get a chip. Use it when the set of possible values is open-ended.

Purpose

TagsInput collects a list nobody can enumerate up front — labels, codes, keywords. Typing is the point: if the valid values are a known list, picking beats typing — use Multi-select for several from a list, or Combobox for one from a searchable list. For a single free-form value, that is an Input.

Enter or comma commits the draft as a chip; Backspace on an empty field removes the last one. Duplicates are rejected case-insensitively with an inline error, and blurring the field commits whatever was typed so half-entered tags are not lost.

dentaloptical

Press Enter or comma to add; Backspace removes the last.

Validation and limits

Pass validate to reject candidates with your own message (return null to accept), and maxTags to cap the list — the text field hides once the cap is reached and returns when a tag is removed. The component can be controlled (value/onValueChange) or uncontrolled (defaultValue):

Format validation with a cap
<div className="grid max-w-md gap-1.5">
  <Label htmlFor="corp-codes">Corporate codes (max 4, format C0000)</Label>
  <TagsInput
    inputId="corp-codes"
    defaultValue={["C3167"]}
    maxTags={4}
    placeholder="e.g. C3167"
    validate={(tag) =>
      /^C\d{4}$/.test(tag) ? null : `"${tag}" is not a valid corporate code (C0000).`
    }
    onValueChange={setCodes}
  />
</div>

States

Empty, filled, at limit and disabled below. The error state is transient — it appears when a duplicate or a validate rejection is committed, turns the border --destructive, and clears on the next keystroke. It cannot be set from outside; for form-level errors wrap the field in your form's error presentation instead.

dentaloptical

gpdental

dentaloptical

Structure

PropertyValue
Containermin-height 40px (min-h-10), grows as chips wrap
Padding8px horizontal, 6px vertical; 6px gap between chips
Border1px --input · error --destructive · shadow --shadow-1
Radius--radius-md
Focusborder --ring + 2px --ring at 40% (focus-within)
Chipssecondary Badge; 13px close glyph remove button
Text field14px, min-width 8rem; placeholder only while the list is empty
Error text12px --destructive-text, 6px below the container
Disabled50% opacity, not-allowed cursor

Best practices

Do

  • Give the field a visible Label targeting inputId — or set inputLabel when a visible label genuinely cannot fit.
  • Use validate to enforce a format at entry time — an error next to the keystroke beats one at submit.
  • Cap unbounded lists with maxTags when downstream systems have a limit.
  • Tell users the commit keys ("Press Enter or comma to add") in a hint — the pattern is not universal.

Don't

  • Use it for values from a known list — that is Multi-select.
  • Rely on the placeholder as the label — it disappears after the first tag.
  • Re-validate for duplicates in validate — case-insensitive duplicate rejection is already built in.

Accessibility & keyboard

  • The inner text field takes its accessible name from a visible <Label htmlFor> targeting inputId; without one, the inputLabel prop (default "Add a tag") supplies an aria-label fallback.
  • Each chip's remove control is a real button named "Remove tag".
  • A rejected commit sets aria-invalid on the text field and links the message via aria-describedby (id {inputId}-error). The message is a polite live region, so it is announced the moment it appears — focus never leaves the field.
  • The container is a click-to-focus surface only; the text field inside is the sole tab stop for entry, so keyboard users lose nothing.
  • Disabled sets aria-disabled on the container and disables the field and every remove button.
  • Keyboard: Enter or comma commits the draft; Backspace on an empty field removes the last tag; blur commits whatever was typed; Tab moves through each chip's remove button to the text field.

Props

PropTypeDefaultDescription
valuestring[] | undefined—Controlled list of tags.
defaultValuestring[] | undefined—Uncontrolled initial tags.
onValueChange((tags: string[]) => void) | undefined——
validate((tag: string, current: string[]) => string | null) | undefined—Reject a candidate tag by returning an error message (null accepts).
placeholderstring | undefined——
disabledboolean | undefined——
maxTagsnumber | undefined—Maximum number of tags; input hides when reached.
inputLabelstring | undefined"Add a tag"Accessible name for the text field. A placeholder is not a label — it disappears on first keystroke and is ignored by some screen readers. Pass `inputId` and your own `<Label htmlFor>` instead when the field has a visible label; this is the fallback for when it does not.
inputIdstring | undefined—`id` for the inner text field, so a visible `<Label htmlFor>` can target it.

On this page