{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tag-input",
  "title": "Tag Input",
  "author": "VenusUI",
  "description": "Add tags with Enter or comma and remove them with Backspace or their buttons.",
  "dependencies": [
    "lucide-react"
  ],
  "files": [
    {
      "path": "registry/default/ui/tag-input.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { X } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface TagInputProps {\n  /** Visible label for the field. */\n  label: string\n  /** Controlled tags. */\n  value?: string[]\n  defaultValue?: string[]\n  onValueChange?: (tags: string[]) => void\n  /** Maximum number of tags. */\n  max?: number\n  placeholder?: string\n  className?: string\n}\n\n/**\n * Type and press Enter or comma to add a tag; Backspace in an empty field\n * removes the last one. Each tag has a labelled remove button, and changes\n * are announced to screen readers. Duplicates are ignored.\n */\nfunction TagInput({ label, value: controlled, defaultValue = [], onValueChange, max, placeholder = \"Add a tag…\", className }: TagInputProps) {\n  const [internal, setInternal] = React.useState(defaultValue)\n  const [draft, setDraft] = React.useState(\"\")\n  const [announcement, setAnnouncement] = React.useState(\"\")\n  const tags = controlled ?? internal\n  const id = React.useId()\n  const full = max !== undefined && tags.length >= max\n\n  function update(next: string[], message: string) {\n    if (controlled === undefined) setInternal(next)\n    onValueChange?.(next)\n    setAnnouncement(message)\n  }\n\n  function add(raw: string) {\n    const tag = raw.trim()\n    if (!tag || tags.includes(tag) || full) return\n    update([...tags, tag], `Added ${tag}`)\n    setDraft(\"\")\n  }\n\n  return (\n    <div data-slot=\"tag-input\" className={cn(\"w-full space-y-1.5\", className)}>\n      <label htmlFor={id} className=\"text-sm font-medium\">\n        {label}\n      </label>\n      <div className=\"flex min-h-10 flex-wrap items-center gap-1.5 rounded-lg border px-2 py-1.5 focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50\">\n        <ul className=\"contents\">\n          {tags.map((tag) => (\n            <li key={tag} className=\"inline-flex items-center gap-1 rounded-md bg-muted py-0.5 pr-1 pl-2 text-sm\">\n              {tag}\n              <button\n                type=\"button\"\n                aria-label={`Remove ${tag}`}\n                onClick={() => update(tags.filter((t) => t !== tag), `Removed ${tag}`)}\n                className=\"inline-flex size-4 items-center justify-center rounded-sm text-muted-foreground outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring\"\n              >\n                <X aria-hidden=\"true\" className=\"size-3\" />\n              </button>\n            </li>\n          ))}\n        </ul>\n        <input\n          id={id}\n          value={draft}\n          disabled={full}\n          placeholder={full ? `Up to ${max} tags` : placeholder}\n          onChange={(event) => {\n            const text = event.target.value\n            if (text.endsWith(\",\")) add(text.slice(0, -1))\n            else setDraft(text)\n          }}\n          onKeyDown={(event) => {\n            if (event.key === \"Enter\") {\n              event.preventDefault()\n              add(draft)\n            } else if (event.key === \"Backspace\" && !draft && tags.length > 0) {\n              const last = tags[tags.length - 1]\n              update(tags.slice(0, -1), `Removed ${last}`)\n            }\n          }}\n          onBlur={() => add(draft)}\n          className=\"min-w-24 flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed\"\n        />\n      </div>\n      <p aria-live=\"polite\" className=\"sr-only\">\n        {announcement}\n      </p>\n    </div>\n  )\n}\n\nexport { TagInput, type TagInputProps }\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "inputs",
    "forms"
  ],
  "type": "registry:ui"
}