Skip to main content
  1. Docs
  2. Components
  3. 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

otp-input.tsx
// 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.

PropTypeDefaultWhat it does
lengthnumber6How many characters.
groupsreadonly 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 · onValueChangestring—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.
maskbooleanfalseHides the characters as they're typed.
aria-labelstring—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-slotElementWhat 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.

verify.tsx
<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>
Next — OTP inputAccessibility