Signer page kit
One-time code
Six boxes over one real input, so paste, autofill and screen readers work. Completes on the last digit.
- In the signer page, not yet in the package
- AGPL-3.0-only
- Client only · no backend
Theme
The CSS variables this sets
:root {
--signing-accent: #3157e8;
--sig-accent: #3157e8;
--sig-accent-soft: color-mix(in oklab, #3157e8 14%, white);
--sig-radius: 8px;
--radius-control: 8px;
--radius-panel: 12px;
--font-sans: var(--font-inter), ui-sans-serif, system-ui, sans-serif;
}In the signer page kit, set the accent with accentProps(accent) on the element around the surface; it sets data-signing-accent and --signing-accent. The secure elements take the same values as a checked appearance object instead.
Default
Type or paste. onComplete fires when the last digit arrives.
Type or paste six digits.
tsx
import { useState } from "react";
import { OtpInput } from "@/components/signing";
export function Example() {
const [code, setCode] = useState("");
return (
<div>
<label className="label" htmlFor="otp">
Verification code
</label>
<OtpInput id="otp" value={code} onChange={setCode} onComplete={(c) => console.log("check", c.length)} />
</div>
);
}
Error: wrong code
The code is wrong or has expired.
tsx
import { OtpInput } from "@/components/signing";
export function Example() {
return (
<div>
<label className="label" htmlFor="otp">
Verification code
</label>
<OtpInput id="otp" value="123456" onChange={() => {}} invalid describedBy="otp-error" />
<p id="otp-error">The code is wrong or has expired.</p>
</div>
);
}
Checking
Busy: read-only, but still focusable and readable.
Checking…
tsx
import { OtpInput, Spinner } from "@/components/signing";
export function Example() {
return (
<div>
<label className="label" htmlFor="otp">
Verification code
</label>
<OtpInput id="otp" value="482913" onChange={() => {}} busy />
<p>
<Spinner /> Checking…
</p>
</div>
);
}
Disabled
tsx
import { OtpInput } from "@/components/signing";
export function Example() {
return <OtpInput id="otp" value="" onChange={() => {}} disabled />;
}
Four digits
tsx
import { useState } from "react";
import { OtpInput } from "@/components/signing";
export function Example() {
const [pin, setPin] = useState("");
return <OtpInput id="pin" value={pin} onChange={setPin} length={4} />;
}
Installation
npx shadcn@latest add …
Not published yet
Not in the registry (packages/ui/registry.json) yet.
Props
className and children are left out: every component that takes them passes them on.
OtpInput
| Name | Type | Default | Description |
|---|---|---|---|
| value | string | The digits so far. | |
| onChange | (v: string) => void | Digits only. | |
| onComplete | (v: string) => void | Called when the last digit arrives. | |
| busy | boolean | false | Checking: read-only but still focusable and readable. |
| invalid | boolean | false | Red boxes; pair with describedBy. |
| length | number | 6 | Number of digits. |
| id | string | Required: the id of the real input, for its label. | |
| describedBy | string | Id of the error or hint text. | |
| disabled | boolean | false | Not usable at all. Prefer busy while checking. |
Accessibility
- One real input with autocomplete=one-time-code: the browser can fill it from the email or SMS.
- Give it a label with htmlFor, and point describedBy at the error text. Busy keeps it focusable and readable.