ValyroUI Русская версия

OTP Input

One-time code entry. Free, MIT · Forms and input › Numbers, codes and masks

The code is one string with no gaps: a box can only be filled after the ones before it, so focus is redirected to the first empty box. id, aria-describedby and aria-invalid go to the inputs (id to the first).

Installation

npx valyro-cli@latest add otp-input
npx shadcn@latest add https://valyro.xyz/r/otp-input.json
npm install valyro-ui

import 'valyro-ui/styles.css';
import { OTPInput } from 'valyro-ui';

Props

PropTypeDefault
lengthnumber6Number of boxes.
valuestringControlled value; use with onValueChange.
defaultValuestring''Initial value when uncontrolled.
onValueChange(value: string) => voidCalled with the new value when it changes.
onComplete(value: string) => voidCalled once every box is filled.
type'numeric' | 'alphanumeric''numeric'Characters kept from typing and paste: digits only (numeric keypad on phones), or Latin letters and digits.
separatorbooleanfalseDraw a dash between the two halves.
invalidbooleanfalseDanger borders and a shake on every box; sets aria-invalid on the inputs.
disabledbooleanfalseDisables every box; the code is not submitted with the form.
autoFocusbooleanFocus the first box on mount.
namestringSubmits the code with the surrounding form as one string (possibly partial).
requiredbooleanEvery box must be filled for the form to submit; the browser points at the first empty one.
labelsPartial<OTPInputLabels>Overrides for the built-in English text; keys left out keep their defaults.

Related components

Previous: Number Input · Next: Phone Input · All Forms and input