InputOTP
One-time code entry with platform code autofill.
- Native host
- New in 0.1
import { InputOTP, inputOTPPrimitive } from "nitro-ui-sdk/input-otp";- HeroUI Native
- InputOTP
- Expo UI
- No counterpart

Light 
Dark
On this page
InputOTP captures a verification or access code with one native editor. The digits appear in visual slots while the OS handles focus, the number keyboard, paste and autofill.
Anatomy
import { InputOTP } from "nitro-ui-sdk/input-otp";
<InputOTP.Root label="Access code, 4 digits" length={4}>
<InputOTP.Slots>
{[0, 1, 2, 3].map((index) => <InputOTP.Slot key={index} index={index} />)}
</InputOTP.Slots>
</InputOTP.Root>;
| Part | Description |
|---|---|
Root |
Owns the code and overlays the one native editor. |
Slots |
Arranges the decorative slots. |
Slot |
Shows one digit and the active caret. |
Usage
import { InputOTP } from "nitro-ui-sdk/input-otp";
<InputOTP.Root label="Verification code, 6 digits" onComplete={(code) => void code} />;
Variants and sizes
Choose outline for a 1 pt field border or filled for a secondary surface. The visible heights are 36 pt (sm), 44 pt (md), and 52 pt (lg). Compact one-line fields keep a 44 pt touch target. Use length for the number of slots. Keep codes as strings to preserve leading zeroes.
States
The focused editor uses the focus border. Invalid fields use the danger border. Disabled fields reduce opacity and reject editing actions. The current slot tracks the native caret. Pasted input keeps digits in order and fills up to the configured length.
Controlled
Pass defaultValue for a local value or value with onValueChange to own it. The editor reconciles to the owner’s value after each edit, including a declined request.
import { useState } from "react";
import { InputOTP } from "nitro-ui-sdk/input-otp";
export function Example() {
const [value, setValue] = useState("");
return <InputOTP.Root label="Verification code, 6 digits" value={value} onValueChange={setValue} />;
}
Props
InputOTP.Root
| Prop | Type | Default | Description |
|---|---|---|---|
label |
string |
Required | Localized name spoken by assistive technology. |
hint |
string |
— | Additional instructions spoken with the field. |
error |
string |
— | Validation message spoken with the field. |
invalid |
boolean |
false |
Applies the invalid appearance. A nonempty error also marks it invalid. |
disabled |
boolean |
false |
Disables editing and reduces opacity. |
variant |
InputOTPVariant |
"outline" |
Field surface appearance. |
size |
InputOTPSize |
"md" |
Visible field size. |
length |
number |
6 |
Number of code digits. Invalid lengths fall back to six. |
onComplete |
(code: string) => void |
— | Runs when a new full code is committed after an accepted edit. |
value |
string |
— | Owner-controlled text. |
defaultValue |
string |
"" |
Initial text in uncontrolled mode. |
onValueChange |
(value: string, details: ActionDetails) => void |
— | Receives the requested text. Call details.preventDefault() to decline. |
onValueCommit |
(value: string, details: ActionDetails) => void |
— | Runs once per accepted edit that changes the value. |
styles |
PartStyles<InputOTPPart, InputOTPVariant, InputOTPSize, InputOTPState> |
— | Style resolvers keyed by part. |
api |
Controller<InputOTPActions> |
— | Attach a controller created with the primitive. |
agentId |
string |
— | Identity for replacing a field in a reused view. |
children |
ReactNode |
— | Compound anatomy override. |
InputOTP.Slots
| Prop | Type | Default | Description |
|---|---|---|---|
part |
InputOTPPart |
— | Override the style key for this part. |
children |
ReactNode |
— | Content to render inside this part. |
InputOTP.Slot
| Prop | Type | Default | Description |
|---|---|---|---|
part |
InputOTPPart |
— | Override the style key for this part. |
index |
number |
Required | Zero-based position in the code. |
Controller API
import { InputOTP, inputOTPPrimitive } from "nitro-ui-sdk/input-otp";
const api = inputOTPPrimitive.createApi();
const field = <InputOTP.Root label="Verification code, 6 digits" api={api} />;
// Use api.current after the field mounts.
export { field, api };
| Action | Signature | Result |
|---|---|---|
focus |
(source?: ActionSource) => ActionStatus |
Focuses the editor when it is available. |
blur |
(source?: ActionSource) => ActionStatus |
Dismisses native editing. |
setValue |
(value: string, source?: ActionSource) => ChangeStatus |
Requests a new value. |
clear |
(source?: ActionSource) => ChangeStatus |
Requests an empty value. |
Use digit strings of at most length characters for controller edits.
Styles
import { InputOTP } from "nitro-ui-sdk/input-otp";
<InputOTP.Root label="Verification code, 6 digits" styles={{ slot: ({ tokens, state }) => ({ style: { borderColor: state.active ? tokens.colors.focus : tokens.colors.fieldBorder } }) }} />;
Resolvers receive tokens, variant, size, and state. State includes disabled, invalid, focused, complete, filled, and active. The latter two describe each slot when its styles resolve.
Accessibility
One native editor exposes the localized name, editing state and native selection. Include the number of digits in the name. The visual slots and caret are hidden from assistive technology.
Agent API
| Action | Arguments | Notes |
|---|---|---|
focus |
None | Focus the native code editor. |
setValue |
Digit string | Accepts up to the configured length. |
clear |
None | Requests an empty code. |
The snapshot omits the code value and digit progress.
Platform notes
| iOS | Android | |
|---|---|---|
| Implementation | UIKit number-pad editor with the one-time-code content type. | Number EditText with the SMS OTP autofill hint. |
| Verification | Native iOS harness in the example app. | Kotlin is written for Android. The Android NDK is unavailable on this machine, so no Android build was run. |