Skip to content
nexubDesign System
v11.9.0

Components · Form Controls

OTP Input

BetaAdded v5.6.0

One box per digit for verification codes, with paste and one-time-code autofill.

import { OTPInput } from '@nexub/react';
View as Markdown

Playground

Props

size
mode

Try 123456

TSX
<OTPInput onComplete={…} onValueChange={() => setStatus('')} />

Examples

Verification code

Try 123456

Backup code

Enter one of your 12-character backup codes

States

  • Try 123456

    default
  • Try 123456

    disabled
  • Try 123456

    invalid
  • Try 123456

    readOnly
  • Try 123456

    size="sm"
  • Try 123456

    size="md"
  • Try 123456

    size="lg"

Props

Props
PropTypeDefaultDescription
lengthnumber—Number of boxes.
valuestring—The code so far, without gaps.
defaultValuestring—The code so far, without gaps.
onValueChange((value: string) => void)—The code so far, without gaps.
onComplete((value: string) => void)—Called when every box is filled; submit or verify here.
mode'numeric' | 'alphanumeric' | 'backup''numeric'Numeric shows the number keypad on phones.
invalidboolean—Error styling (pair with a FormError) and the disabled state.
disabledboolean—Error styling (pair with a FormError) and the disabled state.
namestring—Submits the code with a form.
aria-labelstring—Group name; each box reads "Digit N of M".
mode: 'backup''numeric' | 'alphanumeric' | 'backup'—11.2: a 12-character recovery code in one field, grouped in fours; the value has no dashes.
autoFocusboolean—11.2: focus the first box on mount.
classNamestring—
readOnlyboolean—Boxes show the value but take no input.
size'sm' | 'md' | 'lg''md'Box size: sm 40px tall, md 48px (default), lg 56px.

Accessibility

Keyboard

  • Type

    Fills the box and moves to the next.

  • Backspace

    Clears the box, or the previous one when empty.

  • ArrowLeft / ArrowRight

    Moves between boxes.

Notes

  • The first box has `autocomplete="one-time-code"`, so the code from an SMS fills every box.