PIN input
ProOne box per character for verification codes, PINs and vouchers, with paste and one-time-code autofill. Not an M3 component (@windmorph/react-pro).
import { PinInput } from '@windmorph/react-pro';Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.
Keyboard
| Key | Action |
|---|---|
| Tab | Moves focus to the code, one field for all the boxes, and on to the next element. |
| Arrow Left or Arrow Right | Move to the previous or next box. Inside the code, that box's character is selected, so typing replaces it. |
| Home or End | Move to the first box, or to the box after the last character. |
| Backspace | Deletes the character in the active box, or the last one when the caret waits after the code. |
- Typing a character fills the active box and moves on. Characters the
type(orpattern) doesn't accept are dropped, and letter codes are upper-cased. - Pasting a code cleans it ("123 456" becomes 123456): a full code replaces the value, a shorter one goes in at the caret.
- Numeric codes open the number pad on phones (
inputMode="numeric"). - The boxes read left to right in right-to-left layouts too, and Arrow Left always moves towards the first box.
Screen reader
- Role
- One text field (
input):type="text", ortype="password"withmask. The boxes are drawn over it and hidden from assistive tech. - Accessible name
- The visible
label, oraria-labeloraria-labelledbywithout one. - States announced
- Invalid (
aria-invalid), required, disabled and read-only. The supporting text and the error message describe the field.
- The error appears in an
alertregion, so it is announced as it appears. The supporting text stays readable to screen readers while the error replaces it on screen. - With
maskthe field is a password field, so the code is never read aloud. - The separators between groups and the required asterisk are hidden from assistive tech.
Focus
- The code is one Tab stop. While it has focus, the active box shows the focus state of an M3 text field (a 2px
primaryborder, orerrorwhen invalid) and an empty active box shows a caret. - A tap or click on a box puts the caret in that box.
Touch target
- The input covers the whole row of boxes, so any tap on the row lands on it. Boxes are at least 48, 56 or 64px tall (
sm,md,lg), 4px less a density step (44px at -3 atmd), and grow with larger text. - On narrow screens the boxes shrink to fit, down to 32px wide each.
Motion
- A new character pops into its box (a scale on the fast spatial spring and a fade on the fast effects spring); the caret blinks as a step, 500ms on and 500ms off; an invalid code shakes the row once, on the default spatial spring.
- Under reduced motion the pop is skipped but new characters still fade in, the caret stays on and nothing shakes. Border colours still fade.
What you need to do
- Give it a visible
labelthat says what code to enter and how long it is ("6-digit code"); usearia-labelonly where a visible label is impossible. - Keep
otpon for codes sent by SMS or email (it setsautocomplete="one-time-code"), and turn it off for PINs, withmask. - When a code is wrong, set
invalidwith anerrorMessagethat says what to do next. - In forced-colours mode the boxes keep system-colour borders, with the active box in
Highlight; keepclassNamesoverrides from removing them.