Components
- Accordion
- Action Bar
- Action Toast
- Alert Banner
- Alert Dialog
- Alert
- Alphabet Index
- Amount Field
- Aspect Ratio
- Attachment
- Availability List
- Avatar
- Badge
- Bank Card
- Breadcrumb
- Bubble
- Button Group
- Button
- Calendar
- Camera Frame
- Card Design Picker
- Card Details
- Card Peek
- Card Stack
- Card
- Carousel
- Chart
- Chat Thread
- Checkbox
- Chip Group
- Choice Tile
- Code Block
- Code Dots
- Collapsible
- Combobox
- Command
- Context Menu
- Copy Field
- Countdown
- Country Select
- Data Table
- Date Field
- Date Picker
- Date Range Picker
- Dialog
- Direction
- Document Paper
- Drawer
- Dropdown Menu
- Empty
- Entity Avatar
- Field
- File Trigger
- File Upload Item
- Hover Card
- Input Group
- Input OTP
- Input
- Item
- Kbd
- Key Value
- Keypad
- Label
- Live Region
- Marker
- Message Scroller
- Message
- Money Amount
- Native Select
- Number Field
- Pagination
- Percent Split Editor
- Phone Field
- Popover
- Progress
- QR Code
- Questionnaire
- Radio Group
- Range Histogram
- Rating
- Resizable
- Scroll Area
- Search Field
- Select
- Separator
- Share Bar
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Sortable List
- Spinner
- Status Timeline
- Step Header
- Steps List
- Swipe Row
- Switch
- Table
- Tabs
- Text Field
- Textarea
- Tier Ladder
- Toggle Group
- Toggle
- Token Search Field
- Tooltip
- Trace
- Transaction Row
- Usage Meter
Registry
1
2
3
4
5
6
import {
InputOTP,
InputOTPGroup,
About#
Input OTP is built on the open-source input-otp library by Guilherme Rodz.
Installation#
pnpm dlx shadcn@latest add @dots/input-otp
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 { REGEXP_ONLY_DIGITS } from "input-otp"
Separator#
Use the <InputOTPSeparator /> component to add a separator between input groups.
import {
InputOTP,
InputOTPGroup,
Disabled#
Use the disabled prop to disable the input.
1
2
3
4
5
6
import { Field, FieldLabel } from "@/components/ui/field"
import {
InputOTP,
Controlled#
Use the value and onChange props to control the input value.
Enter your one-time password.
"use client"
import * as React from "react"
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"
Four Digits#
A common pattern for PIN codes. This uses the pattern={REGEXP_ONLY_DIGITS} prop.
"use client"
import { REGEXP_ONLY_DIGITS } from "input-otp"
Alphanumeric#
Use REGEXP_ONLY_DIGITS_AND_CHARS to accept both letters and numbers.
"use client"
import { REGEXP_ONLY_DIGITS_AND_CHARS } from "input-otp"
Form#
Verify your login
Enter the 6-digit code we sent to your email.
Having trouble signing in? Contact support
"use client"
import { RefreshCwIcon } from "lucide-react"API Reference#
See the input-otp documentation for more information.