{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "otp-input",
  "title": "OTP Input",
  "author": "VenusUI",
  "description": "One-time code entry in separate boxes with paste, autofill and keyboard navigation.",
  "files": [
    {
      "path": "registry/default/ui/otp-input.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface OtpInputProps {\n  /** Number of characters. */\n  length?: number\n  /** Controlled value. */\n  value?: string\n  /** Called with the full value whenever it changes. */\n  onValueChange?: (value: string) => void\n  /** Called once every box is filled. */\n  onComplete?: (value: string) => void\n  /** Accept letters as well as digits. */\n  alphanumeric?: boolean\n  /** Accessible name for the group, e.g. \"Verification code\". */\n  label?: string\n  disabled?: boolean\n  className?: string\n}\n\n/**\n * One-time code entry as separate boxes. Typing moves forward, Backspace moves\n * back, the arrow keys move between boxes, and pasting a whole code fills\n * every box. The first box offers the OS's one-time-code autofill.\n */\nfunction OtpInput({\n  length = 6,\n  value: controlled,\n  onValueChange,\n  onComplete,\n  alphanumeric = false,\n  label = \"Verification code\",\n  disabled,\n  className,\n}: OtpInputProps) {\n  const [uncontrolled, setUncontrolled] = React.useState(\"\")\n  const value = (controlled ?? uncontrolled).slice(0, length)\n  const refs = React.useRef<(HTMLInputElement | null)[]>([])\n  const pattern = alphanumeric ? /[^a-zA-Z0-9]/g : /\\D/g\n\n  function update(next: string) {\n    const clean = next.replace(pattern, \"\").slice(0, length).toUpperCase()\n    if (controlled === undefined) setUncontrolled(clean)\n    onValueChange?.(clean)\n    if (clean.length === length) onComplete?.(clean)\n    return clean\n  }\n\n  function focus(index: number) {\n    refs.current[Math.max(0, Math.min(index, length - 1))]?.focus()\n  }\n\n  function onInput(index: number, raw: string) {\n    const typed = raw.replace(pattern, \"\")\n    if (!typed) return\n    const chars = value.padEnd(length, \" \").split(\"\")\n    // Several characters at once (autofill or paste into one box) fill forward.\n    typed.split(\"\").forEach((char, offset) => {\n      if (index + offset < length) chars[index + offset] = char\n    })\n    const next = update(chars.join(\"\").replace(/\\s+$/, \"\"))\n    focus(Math.min(index + typed.length, next.length, length - 1))\n  }\n\n  function onKeyDown(index: number, event: React.KeyboardEvent<HTMLInputElement>) {\n    if (event.key === \"Backspace\") {\n      event.preventDefault()\n      const chars = value.split(\"\")\n      if (chars[index]) {\n        chars.splice(index, 1)\n        update(chars.join(\"\"))\n        focus(index)\n      } else if (index > 0) {\n        chars.splice(index - 1, 1)\n        update(chars.join(\"\"))\n        focus(index - 1)\n      }\n    } else if (event.key === \"ArrowLeft\") {\n      event.preventDefault()\n      focus(index - 1)\n    } else if (event.key === \"ArrowRight\") {\n      event.preventDefault()\n      focus(index + 1)\n    }\n  }\n\n  function onPaste(event: React.ClipboardEvent<HTMLInputElement>) {\n    event.preventDefault()\n    const next = update(event.clipboardData.getData(\"text\"))\n    focus(next.length)\n  }\n\n  return (\n    <div role=\"group\" aria-label={label} data-slot=\"otp-input\" className={cn(\"flex items-center gap-2\", className)}>\n      {Array.from({ length }, (_, index) => (\n        <input\n          key={index}\n          ref={(node) => {\n            refs.current[index] = node\n          }}\n          value={value[index] ?? \"\"}\n          onChange={(event) => onInput(index, event.target.value.slice(-length))}\n          onKeyDown={(event) => onKeyDown(index, event)}\n          onPaste={onPaste}\n          onFocus={(event) => event.target.select()}\n          inputMode={alphanumeric ? \"text\" : \"numeric\"}\n          autoComplete={index === 0 ? \"one-time-code\" : \"off\"}\n          maxLength={length}\n          disabled={disabled}\n          aria-label={`Character ${index + 1} of ${length}`}\n          className={cn(\n            \"size-11 rounded-lg border bg-transparent text-center font-mono text-lg outline-none transition-colors\",\n            \"focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:opacity-50\"\n          )}\n        />\n      ))}\n    </div>\n  )\n}\n\nexport { OtpInput, type OtpInputProps }\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "inputs",
    "forms"
  ],
  "type": "registry:ui"
}