InputOTP
Native one-time code input with grouped visual slots and sanitized paste.
All components · Theme builder · Implementation source
Live preview
Install
netscript ui:add input-otpUsage and examples
The preview runs this JSX with the installed components. Import any composed primitives from your UI directory.
import { useState } from 'preact/hooks';
import { InputOTP } from '@app/components/ui/input-otp.tsx';
export function Example() {
const [value, setValue] = useState('standard');
const [open, setOpen] = useState(false);
const [notice, report] = useState('');
return (<><div><InputOTP label="Verification code" /></div><p role="status">{notice}</p></>);
}Props
Generated from native deno doc --json --private over the shipped implementation. Compound component props retain their owning interface; native attributes pass through where declared.
| Owner | Prop | Type | Optional | Description |
|---|---|---|---|---|
InputOTPProps | label | string | No | |
InputOTPProps | length | 4 | 6 | Yes | |
InputOTPProps | groups | 1 | 2 | Yes | |
InputOTPProps | value | string | Yes | |
InputOTPProps | defaultValue | string | Yes | |
InputOTPProps | onValueChange | (value: string) => void | Yes | |
InputOTPProps | state | "rest" | "focus" | "disabled" | "invalid" | Yes | |
InputOTPProps | class | string | Yes |
InputOTPProps extends Omit<JSX.InputHTMLAttributes<HTMLInputElement>, "class" | "size" | "value" | "defaultValue" | "maxLength" | "children">Keyboard
| Key | Action |
|---|---|
ArrowLeft/ArrowRight/Home/End | Move the native input selection |
Backspace/Delete | Edit the native code input |
Paste | Replace the native selection with sanitized digits |
Tokens
Semantic contract roles: border/input, destructive/default, radius/input, surface/card, text/fg.
CSS custom properties referenced directly: --ns-border-width, --ns-card, --ns-control-height, --ns-destructive, --ns-fg, --ns-input-border, --ns-muted-fg, --ns-radius-input, --ns-ring, --ns-space-3, --ns-space-4, --ns-text-strong, --ns-weight-strong.
Contract and compatibility
Accessibility pattern: native one-time-code input
- Native controls own keyboard/form behavior. Transient focus/hover is CSS/native; data-state also supports deliberate preview. Client visual/controlled updates require an island.
- One real text input handles selection, autofill and form value; grouped slots are aria-hidden mirrors. content is slot anatomy, not a caller prop. Paste normalizes ASCII digits and preserves native selection replacement.
Design contract values marked planned are not implementation props. The props above describe what ships today.