Forms
Otp input
A one-time-code field: one box per character, one string of state.
Import
import { OTPInput } from '@the_viveksingh/vivek-ui'A verification code
Pasting the whole code fills every box at once, which is how people actually enter these. Backspace walks back, arrows move, and the value is one string rather than N pieces of state.
Paste the whole code and it fills every box at once.
<Field label="Verification code">
<OTPInput length={6} onComplete={verify} />
</Field>Masked and alphanumeric
<OTPInput length={4} mask type="numeric" size="lg" />
<OTPInput length={8} type="alphanumeric" size="sm" />Props
Generated from the package's own type declarations, so this table cannot drift from the code.
| Prop | Type | Default | Description |
|---|---|---|---|
length | number | — | Number of boxes. Default `6`. |
value | string | — | Controlled value. Longer strings are truncated, invalid characters dropped. |
defaultValue | string | — | Uncontrolled initial value. |
onChange | (value: string) => void | — | Called with the whole code on every edit, in both modes. |
onComplete | (value: string) => void | — | Called once the last box is filled. Handy for auto-submit. |
type | 'numeric' | 'alphanumeric' | — | `'numeric'` (default) accepts digits; `'alphanumeric'` also accepts letters. |
mask | boolean | — | Render the characters as dots. |
size | 'sm' | 'md' | 'lg' | — | — |
disabled | boolean | — | — |
readOnly | boolean | — | — |
invalid | boolean | — | Sets `aria-invalid` on every box. Injected by `Field`. |
required | boolean | — | Injected by `Field`. |
name | string | — | Submits the whole code with the form, via one hidden input. |
autoFocus | boolean | — | Focus the first box on mount. |
Every remaining prop is spread onto the root element, so all standard HTML and ARIA attributes work. className and style are merged with the library's own, never replaced, and the ref forwards to the root DOM node.
Rendering
OTPInput declares 'use client' because it needs state, effects or event handlers. Importing it into a Server Component creates a client boundary at this component — everything above it stays on the server.