Native Solid 2 fork. Original documentation and designs © WorkOS; historical posts retain their original context.
One-Time Password Field
A group of single-character text inputs to handle one-time password verification.
Features
Keyboard navigation mimicking the behavior of a single input field
Overriding values on paste
Password manager autofill support
Input validation for numeric and alphanumeric values
Auto-submit on completion
Hidden input to provide a single value to form data
Anatomy
Import all parts and piece them together.
API Reference
Root
Contains all the parts of a one-time password field.
Input
Renders a text input representing a single character in the value.
HiddenInput
Examples
Basic usage
Segmented controls
The Root component accepts arbitrary children, so rendering a visually segmented list is as simple as rendering separators between inputs. We recommend hiding decorative elements from assistive tech with aria-hidden and avoid rendering other meaningful content within Root since each child element is expected to belong to the parent with the group role.
Auto-submit form when password is entered
Use the autoSubmit prop to submit an associated form when all inputs are filled.
Controlled value
Accessibility
At the time of writing, there is no singular established pattern in WCAG guidelines for implementing one-time password fields as separate inputs. The behavior aims to get as close as possible to having the field act as a single input, with a few exceptions to match user expectations based on our initial research, testing, and gathering feedback.
This component is implemented as input elements within a container with a role of group to indicate that child inputs are related. Inputs can be navigated and focused using direction keys, and typing input will move focus to the next input until the last input is reached.
Pasting a value into the field will replace the contents of all inputs, regardless of the currently focused input. Based on our research this seems to align with most user expectations, where values are often pasted from password-managers or an email.