Skip to content
Alea0.1

Forms

OTPField

One-time codes in separate boxes; paste the whole code at once.

Ant Design: Input.OTP

import { OTPField } from '@alea/ui';

Examples

OTPField

Type, paste or let the phone fill it in.

Code we sent to ale@example.com

Masked and with an error

A PIN hides its characters; errors say what to do.

PIN
Recovery code
That code expired. Ask for a new one.

Props

OTPField props

One-time codes in separate boxes: paste the whole code, arrows and Backspace move between boxes (Ant's Input.OTP).

PropTypeDefaultDescription
defaultValuestring''The code to start with.
errorMessageReactNode-The error shown when it is invalid.
isDisabledboolean-Disables every part of it.
isInvalidboolean-Marks it invalid and shows errorMessage.
labelReactNode'Verification code'The visible label ("Verification code").
lengthnumber6Number of characters. Default 6.
maskboolean-Hide the characters (PINs).
namestring-Form field name for the joined value.
onChange((value: string) => void)-Called with the code as it is typed.
onComplete((value: string) => void)-Called when every box is filled.
type"numeric" | "alphanumeric"'numeric'numeric (default) or alphanumeric.
valuestring-The code (controlled).

Accessibility

  • A labelled group; each box says which character it is.
  • The first box has autocomplete="one-time-code", so phones offer the code from SMS.

Keyboard

KeyDoes
TypingFills and moves on
BackspaceClears and moves back
Arrow Left / RightMove between boxes
PasteFills every box

Do and don't

Do

  • Say where the code was sent.

Don't

  • Don't time out without saying so.
Tested with axe, keyboard and screen reader roles