Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Input OTP examples · States

OTP with Loading State Input OTP for React

A one-time code field that shows a spinner while a complete code is verified.

Framework
UI library

Verification takes a moment, and silence looks like nothing happened. This example starts verifying as soon as the sixth digit is typed and shows a Spinner with Verifying code... under the field for two seconds, standing in for the request to your server.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

What starts the verification?

The field's completion callback, which fires once every slot is filled. onComplete fires when the code reaches maxLength.

How is the loading state shown?

A row with our Spinner and the text Verifying code..., rendered only while verifying. The row has role status, so the message is announced.

Is there a real request?

No. A two-second timer stands in for it. Replace it with your API call and turn the loading state off when it settles.

Should the field be locked while verifying?

Often, yes: pass disabled from the same loading state so the code can't change mid-request. The Success State example disables the field once the code is accepted.

How do I show the result?

Follow the loading state with an error, as the Error State example does, or a confirmation, as the Success State example does.

How is the value kept?

In state, written on every change. The value is one string, and onChange receives the next string.