Forms & Inputs
@hacline/ui/otp-inputOTPInput
Handle segmented one-time passcodes inside a single native field.
Usage
Omit children to automatically generate slots from maxLength and optional groups (for example, groups={[3, 3]} inserts a separator between two 3-digit groups).
"use client";
import { useState } from "react";
import { OTPInput } from "@/components/ui/hacline/components/otp-input";
export const Example = () => {
const [completed, setCompleted] = useState(false);
return (
<div className="grid justify-items-center gap-2">
<OTPInput
aria-label="6-digit verification code"
groups={[3, 3]}
maxLength={6}
name="code"
onValueChange={(value) => setCompleted(value.length === 6)}
pattern="digits"
/>
<output className="text-hl-fg-muted text-xs">
{completed ? "Code complete" : "Enter 6 digits"}
</output>
</div>
);
};Alphanumeric Invite Code
Set pattern="alphanumeric" and maxLength={4} to accept both letters and digits across four slots backed by one native field.
"use client";
import { OTPInput } from "@/components/ui/hacline/components/otp-input";
export const Example = () => (
<OTPInput
aria-label="4-character invite code"
maxLength={4}
name="invitation"
pattern="alphanumeric"
/>
);Variants, Sizes & Masking
Switch slot styling with variant ("default" / "filled" / "connected"), adjust slot dimensions with size ("sm" / "md" / "lg"), and hide sensitive PIN digits with mask.
Connected (3-3)
Filled + Masked PIN
Compact (small)
"use client";
import { OTPInput } from "@/components/ui/hacline/components/otp-input";
export const Example = () => (
<div className="grid justify-items-center gap-5">
<div className="grid justify-items-center gap-1.5">
<span className="text-hl-fg-muted text-xs">Connected (3-3)</span>
<OTPInput
aria-label="Connected 6-digit code"
defaultValue="482"
groups={[3, 3]}
maxLength={6}
variant="connected"
/>
</div>
<div className="grid justify-items-center gap-1.5">
<span className="text-hl-fg-muted text-xs">Filled + Masked PIN</span>
<OTPInput
aria-label="Masked 4-digit PIN"
defaultValue="19"
mask
maxLength={4}
variant="filled"
/>
</div>
<div className="grid justify-items-center gap-1.5">
<span className="text-hl-fg-muted text-xs">Compact (small)</span>
<OTPInput
aria-label="Compact 4-digit code"
defaultValue="73"
maxLength={4}
size="sm"
/>
</div>
</div>
);Parts
Pass custom children when you need full layout control.
| Part | Description |
|---|---|
OTPInputGroup | Lays out a run of slots. |
OTPInputSeparator | Drawn between groups, like a dash. |
OTPInputSlot | One character of the code. Without children, it shows the character. |
Props
Prop
Type