Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Input OTP examples · Use Cases

Transaction Confirmation Input OTP for React

A payment confirmation screen with a security notice, a six-digit code and cancel and confirm buttons.

Framework
UI library

Sensitive actions deserve a second factor. This example asks for a code before sending $1,250.00 to John Doe: a heading with the amount and the recipient, an Alert titled Security Check explaining why, the six-digit field, and Cancel and Confirm Transaction buttons side by side.

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

How is the security notice built?

An Alert with a TriangleAlertIcon, an AlertTitle reading Security Check and an AlertDescription that says where the code was sent.

How are the two buttons laid out?

In a row with gap-2, each flex-1 so they share the width: an outline Cancel of type button and a Confirm Transaction submit button.

What does Confirm Transaction do?

With a full code, it disables itself and reads Confirming... while a timer stands in for the request, then reports success. A short code shows Confirmation code must be 6 characters. in FieldError.

What does Cancel do?

It clears the code and any error and reports Transaction cancelled. In your app, close the dialog or go back.

Where do the results appear?

The example shows the result in a status line under the form instead of calling an API. Replace that with your request, and show its error in FieldError when the code is rejected.

How is the code field named?

A FieldLabel with sr-only reads Confirmation code. FieldLabel sets htmlFor to transaction-code, the id on InputOTP, which it passes to its input.