shadcn.io is not affiliated with official shadcn/ui
Input OTP examples · Behavior
OTP with Resend Flow Input OTP for React
A one-time code field with a 60-second countdown before the code can be sent again.
Codes get lost, but a resend button that can be hammered invites abuse. This example counts down from 60 seconds under the field, keeps the Resend Code link disabled until it reaches zero, and then offers it with Didn’t receive the code?. Resending clears the field and restarts the countdown.
Preview
Installation
FAQ
How does the countdown work?
The seconds left live in state, starting at 60. An effect schedules a one-second timer that lowers it by one and clears the timer on cleanup, so it stops at zero and never leaks.
When can people resend?
Only at zero. Until then the link-style Button is disabled and the text reads Resend code in 42s; at zero it reads Didn’t receive the code? and the button works.
What does Resend Code do?
It clears the code and restarts the countdown. Call your API there to send a new code.
How is the resend button styled?
variant link, size sm, and h-auto p-0 so it sits on the text line. It's type button, so it never submits a form.
Related
- Auto-submit OTP Input OTPA one-time code form that submits on its
- Controlled OTP Input Input OTPA controlled one-time code field that
- OTP with Paste Optimization Input OTPA one-time code field with a Paste Code
- Button with Text (Standard)The one filled action
- OTP in Form with Validation Input OTPA one-time code form that checks the code
- OTP with Enhanced Focus Management Input OTPA one-time code field wrapped in a label