Components · Form Controls
OTP Input
One box per digit for verification codes, with paste and one-time-code autofill.
import { OTPInput } from '@nexub/react';Playground
Props
Try 123456
<OTPInput onComplete={…} onValueChange={() => setStatus('')} />Examples
Verification code
Backup code
States
Try 123456
defaultTry 123456
disabledTry 123456
invalidTry 123456
readOnlyTry 123456
size="sm"Try 123456
size="md"Try 123456
size="lg"
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| length | number | — | Number of boxes. |
| value | string | — | The code so far, without gaps. |
| defaultValue | string | — | The code so far, without gaps. |
| onValueChange | ((value: string) => void) | — | The code so far, without gaps. |
| onComplete | ((value: string) => void) | — | Called when every box is filled; submit or verify here. |
| mode | 'numeric' | 'alphanumeric' | 'backup' | 'numeric' | Numeric shows the number keypad on phones. |
| invalid | boolean | — | Error styling (pair with a FormError) and the disabled state. |
| disabled | boolean | — | Error styling (pair with a FormError) and the disabled state. |
| name | string | — | Submits the code with a form. |
| aria-label | string | — | Group name; each box reads "Digit N of M". |
| mode: 'backup' | 'numeric' | 'alphanumeric' | 'backup' | — | 11.2: a 12-character recovery code in one field, grouped in fours; the value has no dashes. |
| autoFocus | boolean | — | 11.2: focus the first box on mount. |
| className | string | — | |
| readOnly | boolean | — | Boxes show the value but take no input. |
| size | 'sm' | 'md' | 'lg' | 'md' | Box size: sm 40px tall, md 48px (default), lg 56px. |
Accessibility
Keyboard
- Type
Fills the box and moves to the next.
- Backspace
Clears the box, or the previous one when empty.
- ArrowLeft / ArrowRight
Moves between boxes.
Notes
The first box has `autocomplete="one-time-code"`, so the code from an SMS fills every box.
On iOS & Android: OTPInput
import { OTPInput } from '@nexub/react-native';
<OTPInput label="Verification code" length={6} onComplete={verify} />Web vs mobile
Same tokens and prop names. Where the platforms differ:
| Web | iOS & Android | |
|---|---|---|
| Fields | One input per digit; the first takes one-time-code autofill. | One field drawn as cells, so SMS autofill works on iOS and Android. |
| Label | Compose Label + control + HelperText (or FormField). | One component: label, helperText and error are props. |
Interactive preview of @nexub/react-native rendered for the web. Native chrome (switches, pickers, Liquid Glass) looks like the platform on a device.
On device

iPhone (iOS simulator)

Pixel (Android emulator)
Screenshots from the latest CI run of the showcase app; the live frame renders the same code for the web.
OTPInput props
| Prop | Type | Default | Description |
|---|---|---|---|
| labelrequired | string | — | Accessible name, e.g. "Verification code". |
| length | number | 6 | — |
| value | string | — | — |
| defaultValue | string | — | 11.8: the starting code of an uncontrolled field. |
| onValueChange | (code: string) => void | — | — |
| onComplete | (code: string) => void | — | Called once all digits are entered. |
| secure | boolean | — | Dots instead of digits (PIN). Turns off one-time-code autofill. |
| error | string | — | Error message under the boxes: red outline, announced, read as the field's hint. |
| invalid | boolean | false | 11.8: red outline, and the field is marked invalid for screen readers. Give error for a message too. |
| disabled | boolean | false | 11.8: dimmed, takes no input, and read as disabled. |
| readOnly | boolean | false | 11.8: shows the code but takes no input. Still focusable. |
| size | 'sm' | 'md' | 'lg' | 'md' | 11.8: box size, as web: sm 44pt tall, md 52pt, lg 56pt (backup: the md, lg and xl field heights). |
| name | string | — | 11.8: field name, set as the input's nativeID so a form library or a test can find it (native has no form submission). |
| autoFocus | boolean | — | — |
| style | StyleProp<ViewStyle> | — | — |
| mode | 'numeric' | 'backup' | — | 11.2: backup is a recovery code: one field of 12 letters and digits (length defaults to
12), shown in groups of four (abcd-efgh-ijkl); the value has no dashes. As on web. 11.8:
the keyboard is a plain-letters one in capitals, with no suggestions. |