验证码输入框

一次性验证码输入框,聚焦环平滑滑动定位,数字逐格滚入,错误时抖动提示,成功时绘制对勾动画。

Enter 123456 to verify.

安装

用 shadcn CLI 添加,或手动复制源码。

$ bunx --bun shadcn add @uilab/otp-input

API 参考

length?
number

Number of slots. Default 6.

6
value?
string
defaultValue?
string
onChange?
((value: string) => void)
onComplete?
((value: string) => void)

Fires once every slot is filled.

label?
string

Optional label rendered above the slots.

hint?
string

Helper text shown below the slots while idle.

successMessage?
string

Message shown below the slots when status is "success".

errorMessage?
string

Message shown below the slots when status is "error".

status?
"idle" | "success" | "error"

External validation feedback. "error" shakes, "success" draws a check.

idle
mask?
boolean

Render dots instead of the typed digits.

false
disabled?
boolean
false
autoFocus?
boolean
false
aria-label?
string

Accessible label for the underlying input.

One-time passcode
className?
string

Keep in mind

Some components on this site are inspired by or recreated from existing work across the web. I'm not here to take credit; just to learn, experiment, and sometimes push things a bit further. If something looks familiar and I forgot to mention you, reach out and I'll fix that right away.