I needed to build a 2FA confirmation screen and I wanted it to behave the way that Apple’s does. Here’s the spec as best as I can tell from Apple’s:
- Typing a letter on the
onkeydown
event moves the focus to the next input. - You can mash 6 integers and they should all register in place.
Backspace
removes the current field, or if the current field is empty, it removes the previous field value and focuses the previous field.- It should be impossible to enter a non-numeric key, and impossible to enter more than one key per field.
Tab
key (as well asShift + Tab
) should work as expected.- Clipboard paste should be accepted, starting at the focused field.
- The only key that should be repeatable when holding down is the
Backspace
.
What this doesn't implement:
- When a focused input isn't selected, typing does nothing. Hard to tell if this is a feature or just an artifact on Apple's end.