Skip to content
Ballpoint

Input OTP

A one-time code, one drawn box a character: typing moves on, backspace goes back, pasting fills them all.

From shadcn/ui
Built on Base UI OTP Field

Installation

pnpm dlx shadcn@latest add @ballpoint/input-otp

Usage

tsx
import { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot } from "@/components/ui/input-otp"

<InputOTP length={6}>
  <InputOTPGroup>
    <InputOTPSlot index={0} />
    <InputOTPSlot index={1} />
    <InputOTPSlot index={2} />
  </InputOTPGroup>
  <InputOTPSeparator />
  <InputOTPGroup>
    <InputOTPSlot index={3} />
    <InputOTPSlot index={4} />
    <InputOTPSlot index={5} />
  </InputOTPGroup>
</InputOTP>

Examples

Verifying a code

Controlled, with an invalid state when the code is wrong.

Enter the 6-digit code we sent you. (Try 123456.)

API reference

length (or maxLength)
default 6
number

How many characters. Add one InputOTPSlot for each.

value / defaultValue
string

The code so far, controlled or not.

onValueChange / onValueComplete
(value: string) => void

Called as it changes, and when every box is filled.

validationType
default "numeric"
"numeric" | "alphanumeric" | "none"

Which characters a box accepts.

mask
default false
boolean

Hide the characters as they are typed.

seed
string | number

Pins the drawing.

Every other prop goes to Base UI's OTP Field.

Pen settings

The drawing also takes draw, roughness, passes, radius, corners, weight and speed, as props or from the nearest InkProvider. What each one does.