OTP Input
FormOne-time password input with individual digit fields and auto-advance.
Responsive viewport — resize the window to explore. Direction and density apply only to this preview. Theme applies to the docs too.
"use client";
import {
InputOTP,
InputOTPGroup,
InputOTPSlot,
InputOTPSeparator,
} from "@dashboardpack/core/components/ui/input-otp";
import { useState } from "react";
import { REGEXP_ONLY_DIGITS } from "input-otp";
export default function InputOtpExample() {
const [code, setCode] = useState("");
return (
<div className="space-y-4">
<p id="otp-label" className="text-sm font-medium">
Verification code
</p>
<InputOTP
maxLength={6}
pattern={REGEXP_ONLY_DIGITS}
value={code}
onChange={setCode}
aria-labelledby="otp-label"
>
<InputOTPGroup>
{[0, 1, 2].map((index) => (
<InputOTPSlot key={index} index={index} />
))}
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
{[3, 4, 5].map((index) => (
<InputOTPSlot key={index} index={index} />
))}
</InputOTPGroup>
</InputOTP>
<p className="text-xs text-muted-foreground">
{code.length === 6
? "Code entered. Connect a backend to verify it."
: "Enter or paste a six-digit code."}
</p>
</div>
);
}Usage
Compose InputOTPGroup and InputOTPSlot for each index. Set maxLength and a digit pattern for numeric codes. Verification must happen in your backend.
import {
InputOTP,
InputOTPGroup,
InputOTPSlot,
InputOTPSeparator,
} from "@dashboardpack/core/components/ui/input-otp";Available in the included @dashboardpack/core package. Copy the complete example from Source code for all imports and state. Add "use client" when using hooks or event handlers. See installation and theming for project setup.
API reference
Common props and defaults. Slot-specific props are named below; native elements also accept their standard HTML attributes. The component TypeScript definitions are the complete type reference.
| Prop | Type / Default | Description |
|---|---|---|
| maxLength | numberDefault: required | Number of accepted characters. |
| value / onChange | string / (value: string) => voidDefault: — | Control the entered code. |
| pattern | stringDefault: — | Accepted character pattern. |
| index (InputOTPSlot) | numberDefault: required | Zero-based character position. |
| disabled | booleanDefault: false | Disable code entry. |