Easeout LabOTP Input
OTP Input
A pill that opens into code slots, verifies, and shakes and clears on a wrong code. Paste and SMS autofill work. Try 123456.
Install
npx shadcn add@easeout/otp-inputDependencies
motiontailwindcss
Tags
InputsFree componentMIT
Usage
After installing, it lives at components/otp-input.tsx
"use client"
import { OtpInput } from "@/components/otp-input"
export default function Example() {
return (
<OtpInput
onVerify={async (code) => {
const res = await fetch("/api/verify", { method: "POST", body: JSON.stringify({ code }) })
return res.ok
}}
onSuccess={() => window.location.assign("/dashboard")}
/>
)
}
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
length | number | 6 | Number of digits. |
onVerify | (code: string) => boolean | Promise<boolean> | code === "123456" | Return true when the code is right. Can be async. |
onSuccess | (code: string) => void | – | Called after the success state has shown. |
label | string | "One-time code, 6 digits" | Accessible name of the input. |
cta, verifying, verified, wrong | string | – | The pill's copy in each state, and the error message. |
sound | boolean | true | Soft key clicks, a knock on a wrong code and a chime on the right one. |
autoplay | boolean | false | Plays a wrong code, then the right one, until someone points at it or focuses it. |
className | string | – | Classes for the wrapper. |