Components
OTP input
Fixed-length one-time code field with one cell per character and a completion callback.
import { Field, OtpInput } from "@openperf/deft";
<Field.Root>
<Field.Label>Verification code</Field.Label>
<OtpInput.Root onValueComplete={verify} />
</Field.Root>;When to use
| Need | Component |
|---|---|
| Verification code of a fixed length | OTP input |
| Any other text, including codes of unknown length | Input |
Value
The value is one string. onValueComplete fires when the last cell is filled: verify the code from it, so the user does not have to press a button.
The cells share the container width equally. By default the field accepts digits only (validationType="numeric") and sets autoComplete="one-time-code".
Label
Wrap the input in a Field and keep its Field.Label, even when the design hides it visually: it names the first cell. The other cells get a translated label such as "Character 2 of 6", so render the component under the Lingui provider.
Invalid
Set invalid on Field.Root to put a danger ring on every cell, and show the reason in Field.Error.
API
Also takes the props of Base UI OTPField.Root, except children.
Prop
Type