Rime

OtpInput

A six-cell one-time code entry with paste, auto-advance and onComplete.

OtpInput is one real input per cell with roving focus. Pasting a full code fills every cell and fires onComplete.

Installation

npx shadcn@latest add KezLahd/rime/otp-input

Also installs: base, field.

Usage

import { OtpInput } from "@/components/ui";

<OtpInput aria-label="Authenticator code" value={code} onChange={setCode} onComplete={verify} />

Examples

Default

API

Generated from the component's TypeScript types and JSDoc (scripts/gen-ui-registry.mjs), so it always matches the source.

OtpInput

OtpInput props
PropTypeDefaultDescription
valueRequiredstring
onChangeRequired(value: string) => void
onComplete(value: string) => voidFires once when every box holds a digit, e.g. to auto-submit.
lengthnumber6
invalidboolean
disabledboolean
autoFocusboolean
aria-labelstringRequired when not inside a <Field group>.
classNamestring

Theme tokens

Per-component tokens are undeclared by default, so the default shown is the fallback the CSS uses. Set one at :root (or in theme.css) to restyle every instance. Live values are read from this page, so they follow the Rime Studio.

OtpInput per-component tokens
TokenDefaultLive value
--field-focus-borderrgba(var(--rgb-brand), 0.75)…
--field-focus-ringvar(--focus-halo)…
--field-focus-ring-invalid0 0 0 4px rgba(var(--rgb-danger), 0.14)…
--field-hover-borderrgba(var(--rgb-brand-deep), 0.3)…

System tokens it reads

OtpInput system tokens
TokenDefaultLive value
--brandtokens.css…
--danger-basetokens.css…
--durtokens.css…
--easetokens.css…
--focus-halotokens.css…
--font-monotokens.css…
--ink-disabledtokens.css…
--ink-headingtokens.css…
--line-inputtokens.css…
--r-mdtokens.css…
--rgb-brandtokens.css…
--rgb-brand-deeptokens.css…
--rgb-dangertokens.css…
--shadow-inputtokens.css…
--surface-solidtokens.css…
--surface-sunkentokens.css…

Accessibility

  • autocomplete="one-time-code" on the first cell lets phones offer the SMS code.

Do and don't

Do

  • Verify on onComplete; don't make users press a button too.

Don't

  • Don't clear the code on a wrong attempt without saying why.

For AI agents

This page as markdown, rendered from the same registry entry. Point an agent at it (or add .md to this page's URL), or at /llms.txt for the index.

Open otp-input.md