Verification code

Takes a six-digit code in separate boxes that behave like one field, including paste.

Refined portVue source: WildVerificationCodeInput.vueStorybook story: Forms/Verification Code Input

Try it

Type a code, step back with Backspace, move with the arrow keys, or paste six digits.

Error
Disabled
<WildVerificationCodeInput
  v-model="code"
/>

When to use

  • Use it for a six-digit code sent to the user, on login and on any action that needs a second factor.
Don’t use it

States

Six boxes that behave as one field.

empty
4
8
2
filling
4
8
2
9
1
3
complete
4
8
2
9
1
3
error
<WildVerificationCodeInput v-model="code" />
A filled box looks like an empty one, so the digits show how far through the code you are. On error all six turn red, because the code is wrong as a whole.

Content

  • Write the error as what happened, in one short sentence: “That code has expired.”
  • Clear the error as soon as the code changes, because the field keeps it until you do.

Accessibility

Each box is its own input, named “Digit 1 of 6” and so on, inside one group. The error message is announced when it appears.

KeyWhat it does
A digitFills the box and moves to the next one.
BackspaceClears the box. On an empty box, clears the one before and moves there.
← / →Moves to the previous or next box.
PasteFills from the first box, then focuses the next empty one.
TabMoves through the boxes, then out.

Props

PropTypeDefaultDescription
v-modelstring—The code, up to six digits.
errorstring—Message under the boxes. Turns all six red.
disabledbooleanfalseBlocks all six boxes.

Tokens

TokenValueWhere it lands
--radius-lg8pxEach box, the same as every field.
--global-blue-1000#1877F2The 2px edge of the box with the caret, and the caret itself. 4.23:1; the cyan was 2.53:1.
--global-neutral-grey-800#ADACB0Any box on hover.
--global-neutral-grey-600#DCDCDEEvery box at rest, empty or filled, 1px.
--color-error#E12121The 2px edge of all six boxes, and the message.
--global-neutral-grey-300#F1F1F1The ground when disabled.
--font-size-2xl20pxThe digits.
--font-weight-medium475The digits.