Skip to content

shadcn.io is an independent project built on shadcn/ui

Free

OTP with Success State Input OTP for Ark UI

A six-digit code field that locks and shows a check with Code verified successfully! once the code is complete.

Six boxes in two groups of three. When the code is complete, the boxes lock and a check appears with Code verified successfully!

Lock the field after a good code so it is not edited again. A Button can take people to the next step once the check has passed. In React, Ark UI does not verify the code.

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.
Use email insteadNo credit card

Anatomy

Input OTP anatomy: root, group, separator, slot

Usage

<div className="flex flex-col gap-2">
  <InputOTP
    disabled={isSuccess}
    onValueChange={handleValueChange}
    onValueComplete={handleComplete}
    value={value}
  >
    <InputOTPGroup>
      <InputOTPSlot className="bg-background" index={0} />
      <InputOTPSlot className="bg-background" index={1} />
      <InputOTPSlot className="bg-background" index={2} />
    </InputOTPGroup>
    <InputOTPSeparator />
    <InputOTPGroup>
      <InputOTPSlot className="bg-background" index={3} />
      <InputOTPSlot className="bg-background" index={4} />
      <InputOTPSlot className="bg-background" index={5} />
    </InputOTPGroup>
  </InputOTP>
  {isSuccess ? (
    <div
      className="flex items-center gap-2 text-sm text-success"
      role="status"
    >
      <CheckIcon aria-hidden="true" className="size-4" />
      <span>Code verified successfully!</span>
    </div>
  ) : null}
</div>

FAQ

When is the code verified?

When every slot is filled; a half-second timer stands in for the request. onValueComplete fires when every slot is filled.

Why is the field disabled afterwards?

So the accepted code can't be changed. disabled comes from the same success state that shows the message.

How is the confirmation shown?

A row in text-success with a CheckIcon and Code verified successfully!, with role status so it's announced.

What if the code changes before it's verified?

Every change resets the success state, so only a complete code shows the confirmation.

What should happen after success?

Usually move on: close the dialog, sign the person in, or continue to the next step, after a short pause so the confirmation is seen.

How is the value kept?

In state, written on every change. The value is an array of strings, one per slot, and each change arrives as details.value.

API Reference

Input OTP

Sets disabled={isSuccess}, onValueChange={handleValueChange}, onValueComplete={handleComplete}, value={value}, index={0} and index={1}. The rest is on the Input OTP page.