OTP Input
A one-time-code input whose characters roll into place behind a caret that slides from slot to slot.
Type to fill each slot and move to the next one. Backspace clears a slot in place, then steps back on the next press. Arrow keys move between slots, and a caret slides along with you. Pasting a code, or letting the phone autofill one from a text message, drops it straight in. Set the status to turn the slots green, or shake them red on a wrong code.
Options you can pass to customize this component.
lengthnumberHow many boxes to render, so a 4 digit code is length={4}. Any count works.
sizesmmdlgOverall scale of the boxes. Maps to 40px (sm), 48px (md), and 56px (lg), and carries the text, caret, and gaps with it.
valuestringThe current code. Pass it to control the input yourself; leave it out to let the component track its own state.
defaultValuestringStarting code when the input is uncontrolled.
onChange(value: string) => voidFires on every edit with the full code so far.
onComplete(value: string) => voidFires once the last slot is filled.
typenumberslettersbothWhich characters a slot accepts. Anything else is ignored, including on paste.
statusidlesuccesserrorDrives the feedback state. Success traces a green ring around each box in turn, error rings them red and shakes the row once.
maskbooleanHides the characters, like a password field.
disabledbooleanBlocks input and dims every slot.
autoFocusbooleanFocuses the first slot on mount.
classNamestringExtra classes for the row that wraps the slots.
slotClassNamestringExtra classes for each slot, for sizing and colors.
npx shadcn add amitgajare2/ariseui/otp-input1
Enter 123456 to pass. Any other code fails.