Overview
One-Time Password Field provides a specialized input component for entering verification codes, typically sent via SMS or email. It breaks the code into individual character inputs for better user experience.Features
- Individual character inputs for better visualization
- Automatic focus management
- Full keyboard navigation
- Paste support for complete codes
- Customizable input validation
- Works inside forms
- Accessible by default with proper ARIA attributes
Installation
Anatomy
API Reference
Root
Contains all the one-time password field parts.The controlled value of the OTP field.
The value when initially rendered (uncontrolled).
Event handler called when the value changes.
Event handler called when all inputs are filled.
The maximum number of characters for the OTP.
A regex pattern to validate each character. Examples:
[0-9] for digits only, [a-zA-Z0-9] for alphanumeric.The input mode for mobile keyboards.
The name of the field. Submitted with its owning form as part of a name/value pair.
When true, prevents the user from interacting with the field.
When true, indicates that the user must fill the field before submitting the form.
The reading direction. If omitted, inherits from the parent.
Change the default rendered element for the one passed as a child.
Input
A single character input. Render this multiple times based on yourmaxLength.
The index of this input in the sequence (0-based).
Change the default rendered element for the one passed as a child.
HiddenInput
A hidden input that contains the complete value for form submission.Example
Accessibility
The component automatically manages focus and provides proper ARIA labels for screen readers.
Keyboard Interactions
- ArrowLeft - Moves focus to the previous input.
- ArrowRight - Moves focus to the next input.
- Backspace - Deletes the current character and moves focus to the previous input.
- Delete - Deletes the current character.
- Paste - Pastes clipboard content and fills multiple inputs if applicable.
Features
- Automatic focus management between inputs
- Auto-advances to next input on character entry
- Auto-moves to previous input on backspace
- Supports pasting complete codes
- Properly labeled for screen readers