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.
Name the group with aria-label. With numeric, only digits are accepted.
Use value and onChange to keep the code in your own state, and onComplete to react when every box is filled.
With mask, the characters are hidden, like in a password.
Use filled, light, ghost or subtle with a type to change the surface of the boxes.
error turns the boxes red and marks them as invalid. disabled locks them.
| Attribute | Description | Type | Accepted values | Default |
|---|---|---|---|---|
| length | number of boxes | number | - | 6 |
| value | the code, to control the component | string | - | - |
| initialValue | the code at the start | string | - | '' |
| onChange | called with the code each time it changes | (value: string) => void | - | - |
| onComplete | called with the code when every box is filled | (value: string) => void | - | - |
| numeric | accepts only digits and opens the numeric keyboard | boolean | - | false |
| mask | hides the characters | boolean | - | false |
| boxLabel | name of each box for screen readers | (index: number, length: number) => string | - | Character 1 of 6 |
| disabled | disable the component | boolean | - | false |
| error | red boxes, marked as invalid | boolean | - | false |
| type | color of the boxes | NormalTypes | 'default', 'primary', 'secondary', 'success', 'warning', 'error', 'info' | default |
| rounded | round the corners | boolean | - | false |
| filled | filled variant | boolean | - | false |
| light | light variant | boolean | - | false |
| ghost | outline variant | boolean | - | false |
| subtle | subtle variant | boolean | - | false |
| ... | native props, passed to the group div | HTMLAttributes | 'aria-label', 'id', ... | - |
The ref points at the group div.
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.