{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tags-input",
  "title": "Tags Input",
  "type": "registry:ui",
  "files": [
    {
      "path": "packages/registry-native/components/tags-input/TagsInput.tsx",
      "content": "import * as React from 'react'\nimport { View, type TextInput } from 'react-native'\nimport { Chip } from '@/components/ui/chip'\nimport { Input, type InputProps } from '@/components/ui/input'\nimport { cn } from '@/lib/utils'\n\nexport interface TagsInputProps extends Omit<\n  InputProps,\n  'value' | 'defaultValue' | 'onChangeText' | 'editable' | 'submitBehavior'\n> {\n  /** Controlled tags. The owner may refuse a change by not applying it. */\n  value?: string[]\n  defaultValue?: string[]\n  onValueChange?: (tags: string[]) => void\n  /** Characters that commit the draft. A newline always commits too (multi-line paste). Default `[',']`. */\n  delimiters?: string[]\n  disabled?: boolean\n  /** Classes for the outer wrapper that holds the tag list and the field. */\n  wrapperClassName?: string\n}\n\nconst key = (tag: string) => tag.toLocaleLowerCase()\n\n/** Splits on delimiters and newlines. While typing, the last segment is the unfinished draft. */\nconst segments = (text: string, delimiters: string[]) =>\n  delimiters.reduce((acc, d) => acc.split(d).join('\\n'), text).split('\\n')\n\n/** New tags from `candidates`: trimmed, non-empty, and unique case-insensitively against `existing` and each other. */\nfunction newTags(existing: string[], candidates: string[]) {\n  const seen = new Set(existing.map(key))\n  return candidates.map((tag) => tag.trim()).filter((tag) => tag && !seen.has(key(tag)) && seen.add(key(tag)))\n}\n\n/**\n * Free-form tags field. Draft rules:\n * - A commit that adds tags clears the draft (keeping any text typed after the last delimiter)\n *   once the tags are actually rendered. If a controlled owner refuses, the draft keeps the text exactly\n *   as typed, delimiter included, so nothing the user typed is lost.\n * - A commit with only empty or duplicate (case-insensitive) segments adds nothing and clears them:\n *   the tag is already visible.\n */\nexport const TagsInput = React.forwardRef<React.ComponentRef<typeof TextInput>, TagsInputProps>(\n  (\n    {\n      value,\n      defaultValue,\n      onValueChange,\n      delimiters = [','],\n      disabled = false,\n      wrapperClassName,\n      onKeyPress,\n      onSubmitEditing,\n      ...props\n    },\n    ref,\n  ) => {\n    const [internal, setInternal] = React.useState(defaultValue ?? [])\n    const tags = value ?? internal\n    const [draft, setDraft] = React.useState('')\n    // Tags awaiting the owner, plus the draft to show once they render.\n    const pending = React.useRef<{ added: string[]; tail: string } | null>(null)\n\n    // Layout effect: the typed text is swapped for the tail before paint, so a commit never flashes.\n    React.useLayoutEffect(() => {\n      const wait = pending.current\n      if (!wait) return\n      pending.current = null\n      const rendered = new Set(tags.map(key))\n      if (wait.added.every((tag) => rendered.has(key(tag)))) setDraft(wait.tail)\n    }, [tags])\n\n    const change = (next: string[]) => {\n      if (value === undefined) setInternal(next)\n      onValueChange?.(next)\n    }\n\n    const commit = (candidates: string[], tail: string, typed: string) => {\n      const added = newTags(tags, candidates)\n      if (!added.length) return setDraft(tail)\n      pending.current = { added, tail }\n      // Shown until the tags render; stays if a controlled owner refuses.\n      setDraft(typed)\n      change([...tags, ...added])\n    }\n\n    const remove = (index: number) => {\n      if (disabled) return\n      pending.current = null\n      change(tags.filter((_, i) => i !== index))\n    }\n\n    return (\n      <View className={cn('gap-[8px]', wrapperClassName)}>\n        {tags.length ? (\n          <View className=\"flex-row flex-wrap gap-[8px]\">\n            {tags.map((tag, index) => (\n              <Chip key={index} label={tag} disabled={disabled} onRemove={() => remove(index)} />\n            ))}\n          </View>\n        ) : null}\n        <Input\n          ref={ref}\n          {...props}\n          editable={!disabled}\n          value={draft}\n          // RN docs: 'submit' sends onSubmitEditing without blurring, so the keyboard stays up for the next tag.\n          submitBehavior=\"submit\"\n          onChangeText={(text) => {\n            if (disabled) return\n            pending.current = null\n            const parts = segments(text, delimiters)\n            if (parts.length === 1) return setDraft(text)\n            // trimStart: \"a, b\" should leave \"b\", not \" b\", in the field.\n            commit(parts.slice(0, -1), parts[parts.length - 1].trimStart(), text)\n          }}\n          onSubmitEditing={(event) => {\n            // Native submission can include a final IME/autocorrect edit before React renders its draft.\n            const text = event.nativeEvent.text\n            if (!disabled) commit(segments(text, delimiters), '', text)\n            onSubmitEditing?.(event)\n          }}\n          // RN docs: onKeyPress fires before onChange, so `draft` is still the pre-key text here.\n          // Android delivers soft-keyboard keys only; hardware-keyboard Backspace will not remove tags there.\n          onKeyPress={(event) => {\n            if (!disabled && event.nativeEvent.key === 'Backspace' && draft === '' && tags.length) {\n              remove(tags.length - 1)\n            }\n            onKeyPress?.(event)\n          }}\n        />\n      </View>\n    )\n  },\n)\nTagsInput.displayName = 'TagsInput'\n",
      "type": "registry:ui",
      "target": "~/components/ui/tags-input/TagsInput.tsx"
    },
    {
      "path": "packages/registry-native/components/tags-input/index.ts",
      "content": "export * from './TagsInput'\n",
      "type": "registry:ui",
      "target": "~/components/ui/tags-input/index.ts"
    }
  ],
  "dependencies": [],
  "devDependencies": [],
  "registryDependencies": [
    "https://native.uipkge.dev/r/native/chip.json",
    "https://native.uipkge.dev/r/native/input.json",
    "https://native.uipkge.dev/r/native/utils.json"
  ],
  "description": "Free-form tags field: commits on submit or delimiter (paste splits), rejects duplicates, removable chips, backspace removes the last tag, controlled refusal.",
  "categories": [
    "control"
  ]
}