Components
- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Kbd
- Label
- Menubar
- Native Select
- Navigation Menu
- Pagination
- Popover
- Progress
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toggle
- Toggle Group
- Tooltip
- Typography
1
2
3
4
5
6
import {
InputOTP,
InputOTPGroup,
InputOTPSlot,
} from "@/components/ui/input-otp";
About
Input OTP is built on top of input-otp by @guilherme_rodz.
Installation
$ pnpm dlx shadcn@latest add https://shadcn-cssinjs.com/r/input-otp.json
Usage
import {
InputOTP,
InputOTPGroup,
InputOTPSeparator,
InputOTPSlot,
} from "@/components/ui/input-otp";<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>Composition
Use the following composition to build an InputOTP:
InputOTP
├── InputOTPGroup
│ ├── InputOTPSlot
│ ├── InputOTPSlot
│ └── InputOTPSlot
├── InputOTPSeparator
├── InputOTPGroup
│ ├── InputOTPSlot
│ ├── InputOTPSlot
│ └── InputOTPSlot
├── InputOTPSeparator
└── InputOTPGroup
├── InputOTPSlot
└── InputOTPSlotPattern
Use the pattern prop to define a custom pattern for the OTP input.
import { REGEXP_ONLY_DIGITS_AND_CHARS } from "input-otp";
<InputOTP maxLength={6} pattern={REGEXP_ONLY_DIGITS_AND_CHARS}>
...
</InputOTP>;"use client";
import { Field, FieldLabel } from "@/components/ui/field";
import {
InputOTP,
InputOTPGroup,Separator
Use the <InputOTPSeparator /> component to add a separator between input groups.
import {
InputOTP,
InputOTPGroup,
InputOTPSeparator,
InputOTPSlot,
} from "@/components/ui/input-otp";Disabled
Use the disabled prop to disable the input.
1
2
3
1
2
3
import {
InputOTP,
InputOTPGroup,
InputOTPSeparator,
InputOTPSlot,
} from "@/components/ui/input-otp";Controlled
Use the value and onChange props to control the input value.
Enter your one-time password.
"use client";
import * as React from "react";
import {
InputOTP,Invalid
Use aria-invalid on the slots to show an error state.
0
0
0
0
0
0
"use client";
import * as React from "react";
import {
InputOTP,Four Digits
A common pattern for PIN codes. This uses the pattern={REGEXP_ONLY_DIGITS} prop.
"use client";
import {
InputOTP,
InputOTPGroup,
InputOTPSlot,Alphanumeric
Use REGEXP_ONLY_DIGITS_AND_CHARS to accept both letters and numbers.
"use client";
import {
InputOTP,
InputOTPGroup,
InputOTPSeparator,Form
Verify your login
Enter the verification code we sent to your email address: m@example.com.
Having trouble signing in? Contact support
import { RefreshCwIcon } from "lucide-react";
import { Button } from "@/components/ui/button";
import {
Card,
CardContent,RTL
To enable RTL support in shadcn/ui, see the RTL configuration guide.
1
2
3
4
5
6
"use client";
import * as React from "react";
import { useTranslation } from "@/components/language-selector";
import type { Translations } from "@/components/language-selector";API Reference
See the input-otp documentation for more information.