OTP input
A one-time code in cells: typing moves on, a paste fills them all, Backspace goes back.
import { OtpInput } from "@forgeron/ui";waitingimport { OtpInput } from "@forgeron/ui";
import { useState } from "react";
export default function Code() {
const [done, setDone] = useState("");
return (
<div style={{ display: "grid", gap: 8 }}>
<OtpInput label="Verification code" group={3} onComplete={setDone} />
<code>{done ? `entered ${done}` : "waiting"}</code>
</div>
);
}API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | Names the group; each cell reads “character 3 of 6” for assistive technology. |
length | number | 6 | How many characters. |
value / defaultValue | string | — | Controlled or not. |
onChange | (value: string) => void | — | On every change. |
onComplete | (value: string) => void | — | Once, when the last cell is filled. |
type | "numeric" | "alphanumeric" | "numeric" | Digits only, or letters too. |
mask | boolean | — | Dots instead of characters. |
group | number | — | A gap every n cells. |
autoFocus | boolean | — | Focus on the first cell. |
disabled | boolean | — | Not editable. |
className | string | — | Extra classes. |