Input OTP
ワンタイムコードの入力欄。1 つの実際の入力欄を個別のマスとして描くため、貼り付け・自動入力・スクリーンリーダーがそのまま機能します。
対応フレームワーク
Angular: 対応 Vue: 対応 React: 対応 React Native: 対応
使い方
We sent a 6-digit code to your email.
<div class="demo-stack" style="max-width: 28rem">
<div soneField [invalid]="wrong()">
<label soneFieldLabel for="demo-otp">Verification code</label>
<sone-input-otp inputId="demo-otp" [(value)]="code" [groups]="[3, 3]"
[invalid]="wrong()" (complete)="check($event)" />
@if (wrong()) {
<p soneFieldError>That code didn’t match. Try 123456.</p>
} @else {
<p soneFieldDescription>We sent a 6-digit code to your email.</p>
}
</div>
<div soneField>
<label soneFieldLabel for="demo-otp-2fa">Authenticator code</label>
<sone-input-otp inputId="demo-otp-2fa" disabled />
</div>
</div>インポート
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.
| 名前 | 型 | デフォルト |
|---|---|---|
lengthHow many characters the code has. | number | 6 |
patternWhat ONE character may be: a RegExp or its source (`SONE_OTP_DIGITS`, `SONE_OTP_ALPHANUMERIC`). | RegExp | string | SONE_OTP_DIGITS |
groupsSlots per group, a separator between groups — `[3, 3]`. Ignored unless it adds up to `length`. | readonly number[] | null | null |
disabled | boolean | false |
invalid | boolean | false |
ariaLabel | string | null | null |
ariaDescribedbyExtra ids for `aria-describedby` on the real input. | string | null | null |
inputId | string | null | null |
name | string | null | null |
value双方向 | string | "" |
| 名前 | 型 |
|---|---|
completeEvery slot is filled by the user (typed, pasted or autofilled). | string |