Components
Input OTP
Built on Base UIA one-time code field with one box per character. Typing moves on and paste fills every box.
Verification code
We sent 6 digits to the number ending in 42.
Installation
npx nook-ui@latest add input-otpPrompt
Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.
Short. For assistants that can run commands in your project.
Add the Nook "Input OTP" component to this project, exactly as Nook ships it.
A one-time code field with one box per character. Typing moves on and paste fills every box.
Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add input-otp`. It writes `components/ui/input-otp.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/input-otp.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:
```tsx
"use client";
import * as React from "react";
import { InputOTP } from "@/components/ui/input-otp";
export default function InputOTPDefault() {
const [done, setDone] = React.useState(false);
return (
<div className="grid gap-3">
<div className="grid gap-1">
<p id="otp-title" className="text-sm font-medium">Verification code</p>
<p className="text-sm text-muted-foreground">We sent 6 digits to the number ending in 42.</p>
</div>
<InputOTP length={6} aria-label="Verification code" onValueChange={() => setDone(false)} onValueComplete={() => setDone(true)} />
<p aria-live="polite" className="h-5 text-sm text-muted-foreground">{done ? "Code received. Checking it now." : ""}</p>
</div>
);
}
```
API
- `InputOTP`: The whole field.
- `length` (`number`): Number of characters. Required.
- `invalid` (`boolean`, default false): Marks every box with `aria-invalid` and a red border.
- `value` (`string`): Controlled value.
- `onValueChange` (`(value: string) => void`): Called on every change.
- `onValueComplete` (`(value: string) => void`): Called when every box is filled.
- `mask` (`boolean`, default false): Hide the characters.
Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: The boxes form a group named by `aria-label` (default "Verification code"), and each box announces its position. Backspace moves back, arrows move between boxes.
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
"use client";
import * as React from "react";
import { InputOTP } from "@/components/ui/input-otp";
export default function InputOTPDefault() {
const [done, setDone] = React.useState(false);
return (
<div className="grid gap-3">
<div className="grid gap-1">
<p id="otp-title" className="text-sm font-medium">Verification code</p>
<p className="text-sm text-muted-foreground">We sent 6 digits to the number ending in 42.</p>
</div>
<InputOTP length={6} aria-label="Verification code" onValueChange={() => setDone(false)} onValueComplete={() => setDone(true)} />
<p aria-live="polite" className="h-5 text-sm text-muted-foreground">{done ? "Code received. Checking it now." : ""}</p>
</div>
);
}Examples
Four-digit PIN
Masked, numbers only.
Verify and resend
Reports back when the last box is filled.
We sent a code to m***@acme.com.
Disabled
Invalid code
Red boxes plus a message that says what to do.
That code has expired. Ask for a new one.
Props
InputOTP
The whole field.
| Prop | Type | Default | Description |
|---|---|---|---|
| length | number | – | Number of characters. Required. |
| invalid | boolean | false | Marks every box with `aria-invalid` and a red border. |
| value | string | – | Controlled value. |
| onValueChange | (value: string) => void | – | Called on every change. |
| onValueComplete | (value: string) => void | – | Called when every box is filled. |
| mask | boolean | false | Hide the characters. |
Accessibility
The boxes form a group named by `aria-label` (default "Verification code"), and each box announces its position. Backspace moves back, arrows move between boxes.
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.