Pin Input

A row of boxes to type a short code, like a verification code or a PIN. Each character goes to its own box and the focus moves ahead by itself.

General

Name the group with aria-label. With numeric, only digits are accepted.

Controlled

Use value and onChange to keep the code in your own state, and onComplete to react when every box is filled.

Masked

With mask, the characters are hidden, like in a password.

Variants

Use filled, light, ghost or subtle with a type to change the surface of the boxes.

Error and disabled

error turns the boxes red and marks them as invalid. disabled locks them.

APIs

PinInput.Props

AttributeDescriptionTypeAccepted valuesDefault
lengthnumber of boxesnumber-6
valuethe code, to control the componentstring--
initialValuethe code at the startstring-''
onChangecalled with the code each time it changes(value: string) => void--
onCompletecalled with the code when every box is filled(value: string) => void--
numericaccepts only digits and opens the numeric keyboardboolean-false
maskhides the charactersboolean-false
boxLabelname of each box for screen readers(index: number, length: number) => string-Character 1 of 6
disableddisable the componentboolean-false
errorred boxes, marked as invalidboolean-false
typecolor of the boxesNormalTypes'default', 'primary', 'secondary', 'success', 'warning', 'error', 'info'default
roundedround the cornersboolean-false
filledfilled variantboolean-false
lightlight variantboolean-false
ghostoutline variantboolean-false
subtlesubtle variantboolean-false
...native props, passed to the group divHTMLAttributes'aria-label', 'id', ...-

Typing and pasting

  • • A character fills its box and moves the focus to the next one. Typing over a filled box replaces its character.
  • • Backspace clears the box. On an empty box, it goes back to the previous one and clears it.
  • • Paste fills the boxes from the one that received it, and what does not fit is dropped. The first box accepts the one time code that a phone offers from a text message in the same way.
  • • Left and Right arrows move between the boxes.
  • • The code has no gaps, so a click on a box past the end goes to the first empty one.

Ref

The ref points at the group div.

Accessibility

The boxes are native text inputs in a group named by aria-label, and each one has its own name, like "Character 3 of 6", which you can translate with boxLabel. The first box has autocomplete="one-time-code", so phones can offer the code from a message. error sets aria-invalid on every box.

Edit this page on GitHub