Input OTP

一次性验证码输入:一个真实的输入框绘制成多个独立格子,因此粘贴、自动填充和屏幕阅读器都能直接使用。

可用框架
  • Angular: 可用
  • Vue: 可用
  • React: 可用
  • React Native: 可用

用法

We sent a 6-digit code to your email.

导入

ts
import {
  SoneInputOtpComponent,
} from "@surface-one/angular/input-otp";

API 参考

SoneInputOtpComponent组件

shadcn's InputOTP approach: ONE real `<input autocomplete="one-time-code">` lies transparent over the slots, so paste, SMS / password-manager autofill, IME and screen readers all see a normal text field; the slots only draw it. The caret is kept at the end — a code is typed or pasted, then erased.

选择器
sone-input-otp
输入
名称类型 默认值
length

How many characters the code has.

number6
pattern

What ONE character may be: a RegExp or its source (`SONE_OTP_DIGITS`, `SONE_OTP_ALPHANUMERIC`).

RegExp | stringSONE_OTP_DIGITS
groups

Slots per group, a separator between groups — `[3, 3]`. Ignored unless it adds up to `length`.

readonly number[] | nullnull
disabledbooleanfalse
invalidbooleanfalse
ariaLabelstring | nullnull
ariaDescribedby

Extra ids for `aria-describedby` on the real input.

string | nullnull
inputIdstring | nullnull
namestring | nullnull
value双向string""
输出
名称类型
complete

Every slot is filled by the user (typed, pasted or autofilled).

string