Copy to clipboard
Installation
Copy to clipboard
npx bearnie add input-otp
npx bearnie add input-otp
bunx bearnie add input-otp
bunx bearnie add input-otp
pnpm dlx bearnie add input-otp
pnpm dlx bearnie add input-otp
yarn dlx bearnie add input-otp
yarn dlx bearnie add input-otp
Copy to clipboard
import InputOTP from "@/components/ui/input-otp/InputOTP.astro";
import InputOTPGroup from "@/components/ui/input-otp/InputOTPGroup.astro";
import InputOTPSlot from "@/components/ui/input-otp/InputOTPSlot.astro";
import InputOTPSeparator from "@/components/ui/input-otp/InputOTPSeparator.astro";
Usage
import {
InputOTP,
InputOTPGroup,
InputOTPSlot,
InputOTPSeparator,
} from "@/components/ui"
<InputOTP maxLength={6}>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP>
Pattern
Use the pattern prop to define what characters are allowed in the OTP input.
Digits only (default)
Copy to clipboard
Alphanumeric
Use pattern="alphanumeric" to accept both letters and numbers.
Copy to clipboard
Examples
Separator
Use the InputOTPSeparator component to add a separator between input groups.
Copy to clipboard
Disabled
Use the disabled prop to disable the input.
Copy to clipboard
Invalid
Use invalid on the slots to show an error state.
Copy to clipboard
Four digits
A common pattern for PIN codes.
Copy to clipboard
Custom separator
You can pass custom content to the separator.
Copy to clipboard
-
Anatomy
InputOTP- The main container that manages OTP stateInputOTPGroup- Groups slots together with connected stylingInputOTPSlot- Individual input slot for each digitInputOTPSeparator- Visual separator between groups
Props
InputOTP
| Prop | Type | Default | Description |
|---|---|---|---|
| maxLength | number | required | Maximum length of the OTP (number of slots) |
| pattern | digits | alphanumeric | string | digits | Pattern to validate input |
| disabled | boolean | false | Disables all slots |
| value | string | - | Initial value |
| name | string | - | Name attribute for form submission |
| class | string | - | Additional CSS classes |
InputOTPGroup
| Prop | Type | Default | Description |
|---|---|---|---|
| class | string | - | Additional CSS classes |
InputOTPSlot
| Prop | Type | Default | Description |
|---|---|---|---|
| index | number | required | Index of the slot (0-based) |
| invalid | boolean | false | Shows error state |
| class | string | - | Additional CSS classes |
InputOTPSeparator
| Prop | Type | Default | Description |
|---|---|---|---|
| class | string | - | Additional CSS classes |