Atoms / OTP input

OTP input

A one-time code in cells: typing moves on, a paste fills them all, Backspace goes back.

import { OtpInput } from "@forgeron/ui";
/01 → Code
waiting
import { 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
PropTypeDefaultDescription
labelstring—Names the group; each cell reads “character 3 of 6” for assistive technology.
lengthnumber6How many characters.
value / defaultValuestring—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.
maskboolean—Dots instead of characters.
groupnumber—A gap every n cells.
autoFocusboolean—Focus on the first cell.
disabledboolean—Not editable.
classNamestring—Extra classes.