- Docs
- Components
- Forms
OTP input
A one-time code in slots. Paste fills them all; the phone's SMS autofill lands in one go.
- Import
- @qeetrix/react/experimental
- Status
- ExperimentalSince 0.0.4
- Renders
<input> per slotServer-rendered- Tested
- WCAG 2.2 AAaxe on every pull request
01
Import
// Experimental: from the package's experimental entry, until it's stable.
import { OTPInput } from "@qeetrix/react/experimental";02
Props
And every native attribute of the element it renders.
| Prop | Type | Default | What it does |
|---|---|---|---|
length | number | 6 | How many characters. |
groups | readonly number[] | — | Splits the slots: [3, 3] shows 123 – 456; they must add up to length. |
size | "md" | "lg" | "md" | md in consoles; lg on sign-in pages. |
value · defaultValue · onValueChange | string | — | The code so far. |
onValueComplete | (value: string) => void | — | Called once every slot is filled: verify here. |
validationType | "numeric" | "alpha" | "alphanumeric" | "none" | "numeric" | What each slot takes. |
mask | boolean | false | Hides the characters as they're typed. |
aria-label | string | — | Without a Field label: names the code. |
disabled · name · required | … | — | As on a form control. |
03
Parts
Each part carries a data-slot, for tests and placement.
| data-slot | Element | What it is |
|---|---|---|
otp-input | <div role="group"> | The slots' group. |
otp-input-slot | <input> | A slot; autocomplete="one-time-code" for SMS autofill. |
04
Verify when it's full
onValueComplete, then the Field's error if it's wrong.
<Field label="Verification code" error={error} description="Sent to +91 98765 •••10.">
<OTPInput onValueComplete={async (code) => setError(await verify(code) ? undefined : "That code isn't right.")} />
</Field>