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 codeThat 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).
| Prop | Type | Default | Description |
|---|---|---|---|
defaultValue | string | '' | The code to start with. |
errorMessage | ReactNode | - | The error shown when it is invalid. |
isDisabled | boolean | - | Disables every part of it. |
isInvalid | boolean | - | Marks it invalid and shows errorMessage. |
label | ReactNode | 'Verification code' | The visible label ("Verification code"). |
length | number | 6 | Number of characters. Default 6. |
mask | boolean | - | Hide the characters (PINs). |
name | string | - | 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. |
value | string | - | 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
| Key | Does |
|---|---|
| Typing | Fills and moves on |
| Backspace | Clears and moves back |
| Arrow Left / Right | Move between boxes |
| Paste | Fills every box |
Do and don't
Do
- Say where the code was sent.
Don't
- Don't time out without saying so.