shadcn.io is not affiliated with official shadcn/ui
Input OTP examples · Standard
Controlled OTP Input Input OTP for React
A controlled one-time code field that shows the code as it's typed.
Controlling the field gives you the code at every keystroke. This example keeps the value in state and shows it under the field: Enter your one-time password while it's empty, then You entered: followed by the digits so far. Use the same wiring to validate, enable a button or submit.
Preview
Installation
FAQ
How is the value controlled?
The code lives in state and is passed to InputOTP with a change handler that writes every change back.
The value is one string, and onChange receives the next string.
How is the code shown under the field?
The value is turned into one string. While it's empty, the line reads Enter your one-time password; otherwise You entered: and the digits.
How do I know when the code is complete?
Check the length in the change handler, or listen for completion.
onComplete fires when the code reaches maxLength.
Related
- Standard OTP Input Input OTPA six-digit one-time code field split
- Auto-submit OTP Input OTPA one-time code form that submits on its
- OTP in Form with Validation Input OTPA one-time code form that checks the code
- OTP with Resend Flow Input OTPA one-time code field with a 60-second
- Input with Character CounterA field that counts the characters typed
- OTP with Enhanced Focus Management Input OTPA one-time code field wrapped in a label