ReScript Shadcn
Get started
  • Installation
Components
  • Accordion
  • Alert
  • AlertDialog
  • AspectRatio
  • Attachment
  • Avatar
  • Badge
  • Breadcrumb
  • Bubble
  • Button
  • ButtonGroup
  • Calendar
  • Card
  • Carousel
  • Chart
  • Checkbox
  • Collapsible
  • Combobox
  • Command
  • ContextMenu
  • DataTable
  • DatePicker
  • Dialog
  • Direction
  • Drawer
  • DropdownMenu
  • Empty
  • Field
  • HoverCard
  • Input
  • InputGroup
  • InputOtp
  • Item
  • Kbd
  • Label
  • Marker
  • Menubar
  • Message
  • MessageScroller
  • NativeSelect
  • NavigationMenu
  • Pagination
  • Popover
  • Progress
  • RadioGroup
  • Resizable
  • ScrollArea
  • Select
  • Separator
  • Sheet
  • Sidebar
  • Skeleton
  • Slider
  • Sonner
  • Spinner
  • Switch
  • Table
  • Tabs
  • Textarea
  • Toast
  • Toggle
  • ToggleGroup
  • Tooltip
  • Typography

Input OTP

Accessible one-time password component with copy paste functionality.

1
2
3
4
5
6

About#

Input OTP is built on top of input-otp by @guilherme_rodz.

Installation#

npx shadcn@latest add @rescript-shadcn/InputOtp

Usage#

<InputOtp maxLength={6}>
  <InputOtp.Group>
    <InputOtp.Slot index={0} />
    <InputOtp.Slot index={1} />
    <InputOtp.Slot index={2} />
  </InputOtp.Group>
  <InputOtp.Separator />
  <InputOtp.Group>
    <InputOtp.Slot index={3} />
    <InputOtp.Slot index={4} />
    <InputOtp.Slot index={5} />
  </InputOtp.Group>
</InputOtp>

Pattern#

Use the pattern prop to define a custom pattern for the OTP input.

;<InputOTP maxLength={6} pattern={InputOtp.regexpOnlyDigitsAndChars}>
  ...
</InputOTP>

Examples#

Separator#

Use the <InputOTPSeparator /> component to add a separator between input groups.

Disabled#

Use the disabled prop to disable the input.

1
2
3
4
5
6

Controlled#

Use the value and onChange props to control the input value.

Enter your one-time password.

Invalid#

Use aria-invalid on the slots to show an error state.

0
0
0
0
0
0

Four Digits#

A common pattern for PIN codes. This uses the pattern={REGEXP_ONLY_DIGITS} prop.

Alphanumeric#

Use REGEXP_ONLY_DIGITS_AND_CHARS to accept both letters and numbers.

Form#

Verify your login
Enter the verification code we sent to your email address: m@example.com.

I no longer have access to this email address.

Having trouble signing in? Contact support

API Reference#

See the input-otp documentation for more information.

@react.component
let make = () => {
  <InputOtp maxLength={6} defaultValue="123456">
@react.component
let make = () =>
  <Field className="w-fit">
@react.component
let make = () =>
  <InputOtp maxLength={6}>
@react.component
let make = () =>
  <InputOtp id="disabled" maxLength={6} disabled={true} value="123456">
@@directive("'use client'")

@react.component
@@directive("'use client'")

@react.component
@react.component
let make = () =>
  <InputOtp maxLength={4} pattern={InputOtp.regexpOnlyDigits}>
@react.component
let make = () =>
  <InputOtp maxLength={6} pattern={InputOtp.regexpOnlyDigitsAndChars}>
@react.component
let make = () =>
  <Card className="mx-auto max-w-md">