Installation
npx logic2b@next add input-otpUsage
import {
InputOTP,
InputOTPGroup,
InputOTPSeparator,
InputOTPSlot,
} from "@/components/ui/input-otp"
<InputOTP aria-label="One-time code" maxLength={6}>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP>
Built on input-otp.
Examples
Digits Only
Pass a pattern to restrict input — REGEXP_ONLY_DIGITS is re-exported by
input-otp.
Controlled
Enter your PIN
Accessibility
- Renders a single real
<input>behind the slots, so browser and password manager autofill of one-time codes (autocomplete="one-time-code") works and the field is announced normally by screen readers. - Fully keyboard operable: typing advances through slots,
Backspacemoves back, and arrow keys plus paste are handled by the underlying input-otp primitive. - Invalid state is driven by
aria-invalid, which styles the active slot with the destructive ring. - Give the underlying field an accessible name with a visible
<label>,aria-labeloraria-labelledby; every bundled example does so explicitly.
Live playground
Edit the component props and inspect the exact JSX before copying it. The preview loads only when this section enters the viewport.
Generated JSX
<InputOTP
maxLength={6}
defaultValue="248135"
aria-label="Verification code"
>
<InputOTPGroup>
<InputOTPSlot
index={0}
/>
<InputOTPSlot
index={1}
/>
<InputOTPSlot
index={2}
/>
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot
index={3}
/>
<InputOTPSlot
index={4}
/>
<InputOTPSlot
index={5}
/>
</InputOTPGroup>
</InputOTP>2
4
8
1
3
5
API reference
Generated from the public TypeScript exports in src/ui/input-otp.tsx.
InputOTP
ComponentProps: React.ComponentProps<typeof OTPInput>InputOTPGroup
ComponentProps: React.ComponentProps<"div">InputOTPSlot
ComponentProps: React.ComponentProps<"div"> & { index: number }| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
index | number | Yes | — | — |
InputOTPSeparator
ComponentProps: React.ComponentProps<"div">Accessibility contract
Machine-readable behavior and consumer responsibilities for input-otp.
- Support
- Primitive-managed
- Pattern
- one-time-code textbox
- input-otp
| Keys | Behavior |
|---|---|
| Backspace | Clear the current slot and move backward. |
| ArrowLeft ArrowRight | Move between code positions where supported. |
Built-in semantics
- A single input owns the value while visual slots mirror caret/invalid state.
Consumer responsibilities
- Provide a label, autocomplete=one-time-code where appropriate and never rely only on SMS access.