OTP input preview

OTP input

The verification code field done right – a gliding focus ring, paste and SMS autofill, a calm shake on errors and a morph into Verified

  • Group
    Special inputs
  • Origin
    Copied · affectUI · source
  • License
    MIT
  • Added
    Oct 18
npx shadcn@latest add @deank/otp-input

The registry stays private. Install from the repo with a GitHub token — see the README.

Usage

import { OtpInput } from "@/registry/components/otp-input/otp-input";

<OtpInput />

Props

NameTypeDefaultDescription
lengthnumber6Number of boxes
separatorboolean | numberfalseA small dash between the boxes – true puts it in the middle, a number after that many boxes
numericbooleantrueDigits only with the numeric keyboard on phones; false allows letters too, shown in capitals
valuestringThe code – makes the field controlled
defaultValuestring""Starting code when uncontrolled
onChange(code: string) => voidEvery change: typing, Backspace, paste, autofill and the clearing after an error
onComplete(code: string) => voidCalled once the last box is filled by the user – the place to start verifying
status"idle" | "verifying" | "error" | "success""idle"Verifying shimmers and locks the field, error shakes and shows the message, success morphs into the pill
errorMessageReactNode"That code didn't work. Try again."Shown below the boxes after an error, until the user types again
clearOnErrorbooleantrueClears the boxes shortly after the shake, ready for the next try
successLabelstring"Verified"Text in the pill on success
onResend() => voidShows "Didn't get a code?" below the boxes with a countdown that becomes a Resend button; clicking restarts the countdown
resendInnumber30Seconds until the code can be resent
align"start" | "center""start"Where the boxes and the lines below them sit
disabledbooleanfalseDims the field and ignores input
autoFocusbooleanfalseFocuses the field on mount (without scrolling)
labelstring"Verification code"Accessible name; the number of digits is added
classNamestringExtra class on the root

When to use

- Two-step sign-in, email or phone verification, confirming a sensitive action with a one-time code - Any short code people copy from an email or SMS – paste and autofill fill every box at once

When not to use

Passwords or free text; codes longer than ~8 characters.

Related

Button · Progress tracker