Skip to Content
⭐️ Leave a star →
ComponentsOTP

OTP

One-time password input with individual slot elements. Auto-advances on type, handles Backspace, fires onComplete when all slots are filled. Supports alphanumeric mode.

Features

Auto-advance on type with Backspace support.
onComplete callback when all slots are filled.
Supports alphanumeric mode.
Can be controlled or uncontrolled.
Supports disabled state.

Example

Try 123456

import { OTP } from '@wire-ui/react' <OTP.Root length={6} onComplete={(code) => console.log(code)}> {Array.from({ length: 6 }).map((_, i) => ( <OTP.Slot key={i} index={i} /> ))} </OTP.Root>

Styling

OTP Slots expose data-active, data-filled, and data-complete. The Root also sets data-complete when all slots are filled.

<OTP.Slot className=" border border-black bg-white data-[active]:ring-4 data-[active]:ring-black/20 data-[complete]:bg-black data-[complete]:text-white data-[disabled]:bg-gray-100 data-[disabled]:opacity-50 " />

Using data attributes

Slots set data-active (focused), data-filled (has value), and data-complete (all slots filled). Root sets data-complete.

/* Active slot glow */ [data-active] { box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.1); } /* Filled slot */ [data-filled] { border-color: #000; } /* All complete */ [data-complete] { background: #000; color: #fff; }

Root props

PropTypeDefaultDescription
lengthnumberrequiredTotal number of slots
valuestringControlled value
defaultValuestring''Initial value for uncontrolled use
onChange(value: string) => voidCalled on every change
onComplete(value: string) => voidCalled when all slots are filled
disabledbooleanfalseDisables all slots
alphanumericbooleanfalseAllows letters in addition to digits

Slot props

PropTypeDescription
indexnumberWhich slot this element represents (0-based)

Root data attributes

AttributeWhen present
data-completeAll slots are filled

Keyboard Interactions

KeyDescription
0-9Enters a digit and auto-advances to the next slot.
a-zEnters a letter when alphanumeric mode is enabled.
BackspaceClears the current slot and moves focus to the previous slot.
ArrowLeftMoves focus to the previous slot.
ArrowRightMoves focus to the next slot.
TabMoves focus out of the OTP input.
Last updated on

MIT License © 2026 wire-ui

OTP – Wire UI