{
  "component": "OTPInput",
  "package": "@blade-ai/weft",
  "import": "import { OTPInput } from \"@blade-ai/weft/components/otp-input\";",
  "status": "stable",
  "version": "0.1.0",
  "updated": "2026-11-24",
  "docs": "/components/otp-input",
  "description": "Lets users enter a short one-time code, one character per slot. One real input behind square, bordered slots; 4 or 6 characters, optional 3 + 3 separator.",
  "props": [
    {
      "name": "label",
      "type": "string",
      "default": null,
      "required": true,
      "description": "Visible label above the slots. Required for accessibility."
    },
    {
      "name": "maxLength",
      "type": "4 | 6",
      "values": [
        4,
        6
      ],
      "default": 6,
      "required": false,
      "description": "Number of slots. Codes over 8 characters use Text Input."
    },
    {
      "name": "pattern",
      "type": "string (RegExp source)",
      "values": [
        "REGEXP_ONLY_DIGITS",
        "REGEXP_ONLY_DIGITS_AND_CHARS"
      ],
      "default": "REGEXP_ONLY_DIGITS",
      "required": false,
      "description": "Allowed characters. REGEXP_ONLY_DIGITS or REGEXP_ONLY_DIGITS_AND_CHARS, both exported from the component."
    },
    {
      "name": "value · defaultValue",
      "type": "string",
      "default": null,
      "required": false,
      "description": "Controlled or uncontrolled value, 0 to maxLength characters matching pattern. Pair value with onChange."
    },
    {
      "name": "onChange",
      "type": "(value: string) => void",
      "default": null,
      "required": false,
      "description": "Fires with the new value."
    },
    {
      "name": "onComplete",
      "type": "(value: string) => void",
      "default": null,
      "required": false,
      "description": "Fires once when the last slot fills. Verify here; no Submit button."
    },
    {
      "name": "separator",
      "type": "boolean",
      "default": false,
      "required": false,
      "description": "Splits 6 slots into 3 + 3. Ignored unless maxLength is 6."
    },
    {
      "name": "validationState",
      "type": "\"none\" | \"error\" | \"success\"",
      "values": [
        "none",
        "error",
        "success"
      ],
      "default": "none",
      "required": false,
      "description": "error sets aria-invalid=\"true\"."
    },
    {
      "name": "helpText",
      "type": "ReactNode",
      "default": null,
      "required": false,
      "description": "Masked destination and resend timer, e.g. \"Sent to +91 98•••• 210 · Resend in 0:24\"."
    },
    {
      "name": "errorText",
      "type": "ReactNode",
      "default": null,
      "required": false,
      "description": "Shown instead of helpText when validationState=\"error\", prefixed \"! \"."
    },
    {
      "name": "successText",
      "type": "ReactNode",
      "default": null,
      "required": false,
      "description": "Shown instead of helpText when validationState=\"success\", prefixed \"✓ \". Prop name: UNDEFINED."
    },
    {
      "name": "necessityIndicator",
      "type": "\"none\" | \"required\" | \"optional\"",
      "values": [
        "none",
        "required",
        "optional"
      ],
      "default": "none",
      "required": false,
      "description": "Marks the field required (*) or optional in the label."
    },
    {
      "name": "isDisabled",
      "type": "boolean",
      "default": false,
      "required": false,
      "description": "Disables the input; opacity 50% on the whole field."
    },
    {
      "name": "isReadOnly",
      "type": "boolean",
      "default": false,
      "required": false,
      "description": "Read-only look: UNDEFINED. Drawn with filled tokens and no caret."
    },
    {
      "name": "isLoading",
      "type": "boolean",
      "default": false,
      "required": false,
      "description": "Verifying after onComplete. Input is read-only with aria-busy; spinner after the slots."
    }
  ],
  "undefined": [
    "Caret blink",
    "Autofill highlight",
    "Pressed token for a slot",
    "Slot success border and background",
    "Read-only look (no tokens)",
    "Resend control (Link vs Button) and timer length",
    "labelPosition=\"left\" for OTP (not built)",
    "Other sizes (small, large, mobile 40px)",
    "successText prop name",
    "\"(optional)\" label wording for necessityIndicator=\"optional\""
  ],
  "sizes": {
    "slot": "36 x 36px (size.36)",
    "padding": "0, content centred",
    "gapBetweenSlots": "0, slots 2..n drop the left border",
    "groupSeparatorGap": "spacing.3 (8px)",
    "separator": "8 x 1px · fill surface.text.gray.disabled",
    "labelSlotsHelpGap": "spacing.3 (8px)",
    "character": "13/20 · typography.fonts.size.1200 / typography.lineHeights.100",
    "label": "13/20 · surface.text.gray.normal",
    "helpText": "12/16 · tracking 0.01em",
    "border": "border.width.thin (1px) · ring border.width.3 + interactive.border.primary.faded",
    "radius": "border.radius.none (themeable via --weft-radius)",
    "caretAndSpinner": "1 x 16px · 16px (8px after the group)",
    "otherSizes": "UNDEFINED"
  },
  "states": [
    {
      "name": "default (empty)",
      "trigger": "value = \"\", not focused",
      "tokens": {
        "bg": "surface.background.gray.subtle",
        "border": "interactive.border.gray.default",
        "label": "surface.text.gray.normal",
        "help": "surface.text.gray.muted"
      }
    },
    {
      "name": "hover",
      "trigger": "pointer over the group, not focused / invalid / disabled",
      "tokens": {
        "border": "interactive.border.gray.highlighted (every slot)"
      }
    },
    {
      "name": "focus-visible · active slot",
      "trigger": "hidden input focused",
      "tokens": {
        "border": "interactive.border.primary.default",
        "ring": "border.width.3 interactive.border.primary.faded",
        "caret": "1 x 16 surface.text.gray.normal"
      }
    },
    {
      "name": "active / pressed",
      "trigger": "pointer down on a slot",
      "tokens": {
        "same": "focus-visible",
        "pressed": "UNDEFINED"
      }
    },
    {
      "name": "filled",
      "trigger": "0 < value.length < maxLength",
      "tokens": {
        "text": "surface.text.gray.normal",
        "border": "interactive.border.gray.default",
        "activeSlot": "next empty slot"
      }
    },
    {
      "name": "pasted / auto-filled",
      "trigger": "paste or SMS / email autofill",
      "tokens": {
        "same": "filled, every slot at once",
        "autofillHighlight": "UNDEFINED"
      }
    },
    {
      "name": "complete",
      "trigger": "value.length === maxLength",
      "tokens": {
        "same": "filled, no active slot, no caret"
      }
    },
    {
      "name": "loading",
      "trigger": "isLoading",
      "tokens": {
        "spinner": "16px surface.icon.gray.muted, spacing.3 after the group",
        "help": "surface.text.gray.muted"
      }
    },
    {
      "name": "success",
      "trigger": "validationState=\"success\"",
      "tokens": {
        "border": "interactive.border.gray.default",
        "help": "feedback.text.positive.intense + ✓",
        "slotSuccess": "UNDEFINED"
      }
    },
    {
      "name": "invalid / error",
      "trigger": "validationState=\"error\"",
      "tokens": {
        "border": "feedback.border.negative.intense (every slot)",
        "text": "surface.text.gray.normal",
        "bg": "surface.background.gray.subtle",
        "errorText": "feedback.text.negative.intense, prefixed \"! \"",
        "focusedSlot": "interactive.border.primary.default + interactive.border.primary.faded"
      }
    },
    {
      "name": "disabled",
      "trigger": "isDisabled",
      "tokens": {
        "bg": "interactive.background.gray.disabled",
        "border": "interactive.border.gray.default",
        "text": "surface.text.gray.muted",
        "opacity": "opacity.600 on the whole field"
      }
    },
    {
      "name": "read-only",
      "trigger": "isReadOnly",
      "tokens": {
        "look": "UNDEFINED",
        "drawnAs": "filled tokens, no caret"
      }
    }
  ],
  "behaviour": {
    "input": "One real <input> with autocomplete=\"one-time-code\", maxLength and pattern, labelled by <label htmlFor>. Slots mirror its value and are aria-hidden.",
    "filter": "Characters that do not match pattern are ignored silently; no error state.",
    "autoAdvance": "After each accepted character the active slot moves to the next. No advance past the last slot.",
    "backspace": "Clears the character before the caret and moves back.",
    "paste": "Fills from slot 1, truncated to maxLength. Never blocked. Spaces, dashes and other punctuation are stripped (\"123-456\" -> \"123456\").",
    "autofill": "autocomplete=\"one-time-code\" lets iOS / Android offer the SMS code; accepting it fills every slot at once.",
    "complete": "When value.length === maxLength, onComplete(value) fires once; verify there and set isLoading. No Submit button.",
    "error": "Set validationState=\"error\" + errorText, keep the digits and focus. After the first complete or submit, re-validate on every change and clear the error as soon as the code is valid.",
    "resend": "helpText shows the masked destination and a m:ss countdown. Resend control and timer length: UNDEFINED.",
    "focusOnMount": "autoFocus targets the OTP input itself (active slot 1), never the resend control.",
    "lengthLimit": "maxLength 4 or 6 only. Codes over 8 characters use Text Input."
  },
  "keyboard": [
    {
      "key": "0-9",
      "action": "Types into the active slot and moves to the next one."
    },
    {
      "key": "Backspace",
      "action": "Clears the current slot and moves to the previous one."
    },
    {
      "key": "← / →",
      "action": "Moves between slots."
    },
    {
      "key": "Cmd / Ctrl + V",
      "action": "Pastes the whole code."
    },
    {
      "key": "Tab",
      "action": "Leaves the code input."
    },
    {
      "key": "Shift + Tab",
      "action": "Leaves the code input backwards."
    },
    {
      "key": "Enter",
      "action": "Native form submit. No extra behaviour; verification runs from onComplete."
    }
  ],
  "accessibility": {
    "summary": "One real input behind presentational slots; the slots are hidden from screen readers.",
    "aria": [
      {
        "element": "<input>",
        "attributes": "native textbox · id linked from <label htmlFor>",
        "when": "Always"
      },
      {
        "element": "<input>",
        "attributes": "aria-describedby=\"{messageId}\"",
        "when": "Help or error text is shown"
      },
      {
        "element": "<input>",
        "attributes": "aria-invalid=\"true\"",
        "when": "validationState = \"error\""
      },
      {
        "element": "<input>",
        "attributes": "aria-busy=\"true\" · readOnly",
        "when": "isLoading"
      },
      {
        "element": "<input>",
        "attributes": "aria-required=\"true\" · disabled",
        "when": "necessityIndicator = \"required\" · isDisabled"
      },
      {
        "element": "slot",
        "attributes": "presentational · aria-hidden=\"true\"",
        "when": "Always"
      },
      {
        "element": "separator",
        "attributes": "role=\"separator\"",
        "when": "separator = true"
      },
      {
        "element": "spinner <svg>",
        "attributes": "aria-hidden=\"true\"",
        "when": "isLoading"
      },
      {
        "element": "resend countdown",
        "attributes": "aria-live=\"polite\"",
        "when": "Announce when resend becomes available, not every second (consumer-rendered)"
      }
    ],
    "contrast": "Digit 19.90:1 · help text 5.28:1 · slot border 3.42:1 (Light). Dark values in Paper."
  },
  "usage": {
    "do": [
      "Use maxLength 4 or 6; split 6 into 3 + 3 only when separator is true.",
      "Set autocomplete=\"one-time-code\" and inputMode=\"numeric\" on the single input (the component does).",
      "Verify inside onComplete and show isLoading until the result returns.",
      "Put the masked destination and resend timer in helpText.",
      "Keep the digits on error and say what to do: \"That code is incorrect\"."
    ],
    "dont": [
      "Build the field from separate Text Inputs.",
      "Use OTP Input for codes over 8 characters, PINs or coupons.",
      "Block paste or autofill.",
      "Add a Submit button for the code.",
      "Add radius, gaps between slots or colours that are not in the states table.",
      "Build anything marked UNDEFINED until it has a decision."
    ]
  },
  "example": "<OTPInput label=\"Verification code\" maxLength={6} separator helpText=\"Sent to +91 98•••• 210 · Resend in 0:24\" onComplete={verify} isLoading={isVerifying} />"
}
