Skip to content
SENVENLI UI

One-time code

Boxes for a one-time verification code, with paste, autofill and a resend cooldown.
A six-digit code
import { OtpField } from "@senvenli/react/form";

Examples

Four digits with resend

The field takes the code; a Button with `useCooldownAction` sends it again after a wait.

A wrong code

The error says what to do next.

Guidelines

When to use it

  • Entering a code sent by text message or email.

Use something else when

  • The code is long, mixed or pasted from elsewhere, with type="number" or text. Input

Accessibility

Built in

  • One input under the boxes, so autofill and screen readers see a single field.
  • The resend countdown is announced.

You provide

  • A label that says where the code was sent.

API reference

OtpField

labelRequired
React.ReactNode
length
4 | 6

4 or 6 digits; 6 splits 3 + 3 with a dash.

description
React.ReactNode
errorMessage
React.ReactNode

Say what to do: "Wrong code. Enter the latest code from your phone."

onComplete
(code: string) => void

Called once the last digit is entered (submit there).

requiredValidation
RequiredValidation

Who says an empty required field is missing: field (default) or app. With app a DS Form's onSubmit runs with the field empty, and the app's own error must clear on change. See {@link RequiredValidation} for the whole contract.

motion
ComponentMotion

auto (follow the device), reduce or none, for this component; the provider's setting otherwise.

Also takes 84 standard DOM and ARIA attributes (id, aria-label, event handlers…).