One-time code slots that take typing, paste and SMS autofill, with an opt-in animation that cascades codes in and a status for verifying.
Install
Add it to your project
Run this in a project set up for shadcn/ui. It writes the files and installs the npm packages.
First time: connect the Infinity UI registry
- Create a personal token on your Tokens page.
- Put it in
.env.localasINFINITYUI_TOKEN. - Add the registry to
components.json:
{
"registries": {
"@infinityui": {
"url": "https://infinityui.io/r/{name}.json",
"headers": {
"Authorization": "Bearer ${INFINITYUI_TOKEN}"
}
}
}
}Using Claude Code, Codex, Cursor, Lovable or v0? See CLI & MCP for a setup prompt.
npm packages it adds
- cn
- @base-ui/react
- @tabler/icons-react
- class-variance-authority
Code
"use client"
import * as React from "react"
import {
InputOTP,
InputOTPGroup,
InputOTPSeparator,
InputOTPSlot,
type InputOTPStatus,
} from "@/components/ui/input-otp"
import { Label } from "@/components/ui/label"
export function InputOTPDemo() {
const [value, setValue] = React.useState("")
const [status, setStatus] = React.useState<InputOTPStatus>("idle")
const timer = React.useRef<ReturnType<typeof setTimeout>>(undefined)
React.useEffect(() => () => clearTimeout(timer.current), [])
function verify(code: string) {
setStatus("loading")
clearTimeout(timer.current)
timer.current = setTimeout(() => {
if (code === "123456") {
setStatus("success")
return
}
setStatus("error")
timer.current = setTimeout(() => {
setValue("")
setStatus("idle")
}, 900)
}, 1200)
}
return (
<div className="flex max-w-full min-w-0 flex-col items-center gap-3">
<Label htmlFor="input-otp-demo">Verification code</Label>
<InputOTP
id="input-otp-demo"
length={6}
variant="separate"
animated
status={status}
value={value}
onValueChange={(next) => {
setValue(next)
setStatus("idle")
}}
onValueComplete={verify}
aria-describedby="input-otp-demo-hint"
>
<InputOTPGroup>
<InputOTPSlot />
<InputOTPSlot />
<InputOTPSlot />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot />
<InputOTPSlot />
<InputOTPSlot />
</InputOTPGroup>
</InputOTP>
<p id="input-otp-demo-hint" className="text-sm text-muted-foreground">
Type or paste 123456 to pass. Anything else fails.
</p>
</div>
)
}
































