`OtpInput` is a one-time-code field: a `role="group"` of real `<input>` boxes, one per character. Spar owns the value (one contiguous string), typing, deleting, paste / SMS autofill and `Field` wiring. Without children the root renders `length` boxes itself. **When to use:** SMS / e-mail verification codes, 2FA codes, short PINs and fixed-length references. Not this — use `takeoff-input` for free text or a password, and `Input.Field mask` for a formatted value of variable length.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Takeoff Otp Input?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/turkishtechnology-takeoff-otp-input)
---
name: takeoff-otp-input
description:
Use the OtpInput component from @takeoff-ui/react-spar to collect a one-time
code in one box per character, with paste and SMS autofill. Use whenever
building, importing, styling or fixing verification-code, 2FA, OTP, PIN or
booking-reference entry fields in a Takeoff / Spar React app.
---
# OtpInput — @takeoff-ui/react-spar
`OtpInput` is a one-time-code field: a `role="group"` of real `<input>` boxes,
one per character. Spar owns the value (one contiguous string), typing,
deleting, paste / SMS autofill and `Field` wiring. Without children the root
renders `length` boxes itself.
**When to use:** SMS / e-mail verification codes, 2FA codes, short PINs and
fixed-length references. Not this — use `takeoff-input` for free text or a
password, and `Input.Field mask` for a formatted value of variable length.
## Setup
Requires the Takeoff provider + token CSS mounted once at the app root (see the
`takeoff-ui` skill). Then:
```tsx
import { OtpInput } from '@takeoff-ui/react-spar';
```
## Compound parts
- `OtpInput` — root; renders `role="group"` and, without children, `length`
boxes in one group.
- `OtpInput.Group` — a joined cluster of boxes, to split a code (e.g. 3 + 3).
- `OtpInput.Slot` — one box (`index` is 0-based; render each index once).
- `OtpInput.Separator` — `aria-hidden` mark between groups; children replace the
default dash.
## Basic usage
```tsx
<OtpInput aria-label="Verification code" />
<Field>
<Field.Label>Verification code</Field.Label>
<OtpInput name="code" value={code} onValueChange={setCode} onValueComplete={verify} />
<Field.Description>We sent it to your phone.</Field.Description>
</Field>
```
## Examples
### Split into groups
```tsx
<OtpInput aria-label="Verification code">
<OtpInput.Group>
<OtpInput.Slot index={0} />
<OtpInput.Slot index={1} />
<OtpInput.Slot index={2} />
</OtpInput.Group>
<OtpInput.Separator />
<OtpInput.Group>
<OtpInput.Slot index={3} />
<OtpInput.Slot index={4} />
<OtpInput.Slot index={5} />
</OtpInput.Group>
</OtpInput>
```
### Letters, hidden PIN
```tsx
<OtpInput aria-label="Booking reference" type="alphanumeric" />
<OtpInput aria-label="PIN" length={4} obscure />
```
## Key props
### `OtpInput` (root)
| Prop | Type | Default | Notes |
| ----------------- | --------------------------------------------- | --------------------------------- | ---------------------------------------------------------- |
| `value` | `string` | - | Controlled code; contiguous, rejected characters dropped. |
| `defaultValue` | `string` | - | Uncontrolled initial code. |
| `onValueChange` | `(value: string) => void` | - | Fires once per change. |
| `onValueComplete` | `(value: string) => void` | - | Fires once each time the last box fills. |
| `length` | `number` | `6` | Box count. |
| `type` | `'numeric' \| 'alphanumeric' \| 'alphabetic'` | `'numeric'` | Accepted characters; `numeric` opens the numeric keyboard. |
| `obscure` | `boolean` | `false` | `type="password"` boxes. |
| `placeholder` | `string` | - | Shown in empty boxes. |
| `size` | `'small' \| 'base' \| 'large'` | `'base'` | Input's scale. |
| `slotLabel` | `string` | `'Character {index} of {length}'` | Box accessible-name template; empty falls back. |
| `name` / `form` | `string` | - | Submits the code through a hidden input. |
| `autoFocus` | `boolean` | `false` | Focus the first box on mount. |
| `invalid` | `boolean` | `false` | Danger borders, `aria-invalid`; inherited from `Field`. |
| `disabled` | `boolean` | `false` | Inherited from `Field`. |
| `readOnly` | `boolean` | `false` | Focusable but not editable; inherited from `Field`. |
| `required` | `boolean` | `false` | `aria-required`; inherited from `Field`. |
### `OtpInput.Slot`
| Prop | Type | Default | Notes |
| ------- | -------- | ------- | ----------------------------------------------------------------------------------------------- |
| `index` | `number` | - | Required 0-based position. Consumer `onKeyDown` / `onPaste` run first; `preventDefault` vetoes. |
## Behavior
- Typing fills the focused box and moves on; Backspace removes the focused (or,
on an empty box, the previous) character and later ones shift left; Delete
removes without moving.
- Focus never rests past the first empty box.
- Paste fills from the focused box; a full-length paste replaces the code. The
first box has `autocomplete="one-time-code"`, so SMS autofill works too.
## Styling hooks
Root: `data-size`, plus Spar's `data-complete` / `data-invalid` /
`data-disabled` / `data-readonly`. Slot: Spar's `data-filled`. Group and
Separator carry only `data-slot`; each part takes `classNames.root` /
`slotProps.root`.
## Accessibility
- Name the group with `aria-label` or a `Field.Label` (clicking it focuses box
1); boxes are named from `slotLabel` and described by the `Field` messages.
- ArrowLeft / ArrowRight / Home / End move between boxes; each box is a tab
stop.
Read `references/full-docs.md` for the full docs page.
## Source
- Docs: `apps/docs/docs/components/otp-input.mdx`
- Component: `packages/react-spar/src/components/otp-input/`
- Spar primitive: `packages/spar/src/components/OtpInput/`