Components/OTP Input
OTP Input
Accessible one-time password input with copy-paste support and keyboard navigation.
Playground
Length
Slot Size
Separator
Disabled
Error
Code
import { useState } from 'react';
import { OTP } from 'irismail/react';
function VerifyForm() {
const [code, setCode] = useState('');
return (
<OTP
value={code}
onChange={setCode}
/>
);
}Examples
Common patterns.
Basic
3
8
4
7
2
9
With Separator
7
4
9
2
8
1
Light Theme
5
2
8
1
4
6
Error State
1
9
2
8
4
7
API
Props for the OTP component.
| Prop | Type | Default |
|---|---|---|
length | number | 6 |
value | string | — |
onChange | (value: string) => void | — |
onComplete | (value: string) => void | — |
theme | "dark" | "light" | "dark" |
slotSize | "sm" | "md" | "lg" | "md" |
separator | boolean | false |
groupSize | number | length / 2 |
disabled | boolean | false |
error | boolean | false |
autoFocus | boolean | false |
classNames | OTPClassNames | — |
Styles API
Customize individual parts with the classNames prop.
| Key | Description |
|---|---|
root | Root container element |
group | Group wrapper containing slots |
slot | Individual digit slot (base state) |
slotFilled | Slot when it contains a digit |
slotActive | Slot when focused/active |
slotError | Slot in error state |
separator | Separator container |
separatorLine | The separator dash/line |
caret | Blinking caret cursor |
<OTP
value={code}
onChange={setCode}
separator
classNames={{
slot: "rounded-none first:rounded-l-md",
slotActive: "ring-2 ring-blue-500",
separator: "mx-4",
separatorLine: "bg-blue-500 w-4",
}}
/>Like what you see?
Check out the docs or star us on GitHub.