A group of single-character text inputs to handle one-time password verification.
import * as React from "react";import { unstable_OneTimePasswordField as OneTimePasswordField } from "radix-ui";const OneTimePasswordFieldDemo = () => (<OneTimePasswordField.Root className="OTPRoot"><OneTimePasswordField.Input className="OTPInput" /><OneTimePasswordField.Input className="OTPInput" /><OneTimePasswordField.Input className="OTPInput" /><OneTimePasswordField.Input className="OTPInput" /><OneTimePasswordField.Input className="OTPInput" /><OneTimePasswordField.Input className="OTPInput" /><OneTimePasswordField.HiddenInput /></OneTimePasswordField.Root>);export default OneTimePasswordFieldDemo;
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
Import all parts and piece them together.
Contains all the parts of a one-time password field.
Renders a text input representing a single character in the value.
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.
Use the autoSubmit
prop to submit an associated form when all inputs are filled.
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.