Input OTP
One-time password input with segmented fields. Install Input OTP from the VLLNT UI registry with the shadcn CLI.
One-time password input with segmented fields. Part of the form family in VLLNT UI, it ships as a machine-readable registry entry — copy the source directly into your app with the shadcn CLI and own it, no runtime dependency on a component library.
Preview
Switch between light and dark to inspect the embedded Storybook preview.
Installation
Add Input OTP to your project with the shadcn CLI. The source lands in your codebase, ready to adapt:
pnpm dlx shadcn@latest add https://ui.vllnt.ai/r/input-otp.jsonSource
"use client";
import { use } from "react";
import { OTPInput, OTPInputContext } from "input-otp";
import { Dot } from "lucide-react";
import { cn } from "../../lib/utils";
const InputOTP = ({
className,
containerClassName,
ref,
...props
}: React.ComponentPropsWithoutRef<typeof OTPInput> & {
ref?: React.Ref<React.ComponentRef<typeof OTPInput>>;
}) => (
<OTPInput
className={cn("disabled:cursor-not-allowed", className)}
containerClassName={cn(
"flex items-center gap-2 has-[:disabled]:opacity-50",
containerClassName,
)}
ref={ref}
{...props}
/>
);
InputOTP.displayName = "InputOTP";
const InputOTPGroup = ({
className,
ref,
...props
}: React.ComponentPropsWithoutRef<"div"> & {
ref?: React.Ref<React.ComponentRef<"div">>;
}) => (
<div className={cn("flex items-center", className)} ref={ref} {...props} />
);
InputOTPGroup.displayName = "InputOTPGroup";
const InputOTPSlot = ({
className,
index,
ref,
...props
}: React.ComponentPropsWithoutRef<"div"> & {
index: number;
ref?: React.Ref<React.ComponentRef<"div">>;
}) => {
const inputOTPContext = use(OTPInputContext);
const slot = inputOTPContext.slots[index];
if (!slot) {
return null;
}
const { char, hasFakeCaret, isActive } = slot;
return (
<div
className={cn(
"relative flex size-10 items-center justify-center border-y border-r border-input text-sm transition-all first:rounded-l-md first:border-l last:rounded-r-md",
isActive && "z-10 ring-2 ring-ring ring-offset-background",
className,
)}
ref={ref}
{...props}
>
{char}
{hasFakeCaret ? (
<div className="pointer-events-none absolute inset-0 flex items-center justify-center">
<div className="h-4 w-px animate-caret-blink bg-foreground duration-1000" />
</div>
) : null}
</div>
);
};
InputOTPSlot.displayName = "InputOTPSlot";
const InputOTPSeparator = ({
ref,
...props
}: React.ComponentPropsWithoutRef<"div"> & {
ref?: React.Ref<React.ComponentRef<"div">>;
}) => (
<div ref={ref} role="separator" {...props}>
<Dot />
</div>
);
InputOTPSeparator.displayName = "InputOTPSeparator";
export { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot };
Stories
Explore every variant and state in the interactive Storybook:
Preview
Switch between light and dark to inspect the embedded Storybook preview.