Menu

OTP input

One-time code / PIN boxes. 2 lengths × 4 states.

We sent a 6 digit code to 01712 345678.

Installation

$ npx uix-ui@latest add otp-input

This copies the file into components/ui/otp-input.tsx in your project. npx shadcn@latest add @uix/otp-input works too.

Usage

otp-input.tsx
import { OtpInput } from "@/components/ui/otp-input";

<div style={{ display: "grid", gap: 12, justifyItems: "center" }}>
  <OtpInput length="6" aria-label="Verification code" onComplete={setDone} />
  <span className="text-body-small text-fg-secondary">{done ? `Code entered: ${done}` : "We sent a 6 digit code to 01712 345678."}</span>
</div>

Props

PropTypeDefaultDescription
length4 | 6"6"
valuestring–The code typed so far (controlled).
defaultValuestring""
onValueChange(value: string) => void–Called on every change with the digits so far.
onComplete(value: string) => void–Called once every box is filled.
errorstring–Error message; also marks the boxes invalid.
helperReact.ReactNode–Text under the boxes.
namestring–Name of a hidden input that carries the code in a form.
disabledbooleanfalse

Everything else is passed to the root element, so className, aria-* and event handlers work as usual.

Dependencies

Installed for you by the CLI.

  • class-variance-authority
  • clsx
  • tailwind-merge
  • lib/utils.ts
esc

↑↓ to navigate · ↵ to select · esc to close