Skip to content
synccn

OTP Input

One-time code field with paste, arrows and grouping.

Enter the 6-digit code. Paste works too.

Playground

Change the props and copy the code. The controls come from the component's TypeScript types.

Props

length6
group3
import { OtpInput } from "@/components/ui/otp-input";<OtpInput />

Installation

$ pnpm dlx shadcn@latest add @synccn/otp-input

First time in this project? Connect synccn with one command.

Usage

import { OtpInput } from "@/components/ui/otp-input";<OtpInput length={6} onComplete={verify} />

API reference

Generated from the component's TypeScript types, so it always matches the code.

OtpInput

One-time code field. Supports paste, arrows, backspace and a grouped layout.

  • length
    number

    Default 6

    Number of digits.

  • group
    number

    Default 3

    Digits per group, separated by a dash. 0 for none.

  • onComplete
    (code: string) => void

    Called when every digit is filled.

  • invalid
    boolean

    Shows the error style.

  • className
    string

    Extra classes for the root element.

Dependencies

Read from the component's imports when the site builds. The CLI installs all of these for you.

Helpers

npm packages

Keyboard

  • ←or→Move between boxes
  • BackspaceClear the box, or go back to the previous one

Accessibility

  • Pasting a whole code fills every box. The boxes share one group label.

From the source

Read from this component's code when the site builds, so it can't drift.

  • ARIA roles: group
  • ARIA attributes: aria-label
  • Keys handled: ArrowLeft, ArrowRight, Backspace