@objectifthunes/whiteboard
FORMS

OtpInput

One-time-code entry: one box per character, with the paste, backspace and arrow behaviour 2FA fields need.


PREVIEW

Try 123456. Paste a whole code to fill every box.

value = ""

SOURCE
import { OtpInput, Field } from '@objectifthunes/whiteboard'

<Field label="Verification code" hint="We sent a 6-digit code to your email.">
  <OtpInput
    value={code}
    onChange={setCode}
    onComplete={verify}       // fires when the last box fills
    invalid={rejected}
    autoFocus
  />
</Field>

{/* alphanumeric codes */}
<OtpInput value={code} onChange={setCode} length={8} inputMode="text" />
NOTES

The whole code lives in one string, so it is one form value and one request body field rather than six pieces you have to reassemble.

Pasting a code from an authenticator or an email fills every box at once. Dropping all but the first character is the failure that makes these fields infuriating, so paste is intercepted and split.

Backspace on a filled box clears it and stays put; on an empty box it steps back and clears that one. Arrows move between boxes, and focusing a box selects its character so typing replaces rather than appends.

autoComplete="one-time-code" is set on the first box, which is what lets iOS and Android offer the SMS code straight from the keyboard. onComplete only fires when every position is filled, so clearing a middle box cannot trigger a premature verify.