UI

One-time code

A labelled numeric verification code with paste, autofill and keyboard navigation.

Read Markdown

Web 0.2.0

Enter the six-digit code. You can paste it here.
  • Defaultlight7.93 : 1AA 4.5dark9.07 : 1AA 4.5
  • Keyboard1234ArrowLeftArrowRightBackspace
  • measured on 0.2.0
npx shadcn@latest add @maeso/one-time-code
Size
16.6 kB gzipmeasured on 0.2.0

Usage

Provide a label and the expected numeric code length. Handle onChange to store the code and onComplete to validate it. Completion does not submit automatically.

Accessibility

Keep paste and one-time-code autofill available. Each slot has a name; typing advances focus and arrow keys move between slots. Describe validation errors in text.

When to use

Use for a numeric verification code with a known length. Use Input for passwords or codes that may contain letters.

Install

Add this registry to your project's components.json once, before the first install. Keep your existing settings and other registries.

{
  "registries": {
    "@maeso": "http://127.0.0.1:4321/r/{name}.json"
  }
}

Then install the registry's default theme once, and import its sheet in the CSS entry that imports Tailwind. It paints every item from this registry.

npx shadcn@latest add @maeso/maeso
@import "./styles/theme.web.css";
npx shadcn@latest add @maeso/one-time-code

Props

OneTimeCode

PropTypeRequiredDescription
labelReactNodeyes
defaultValuestring | undefinedno
disabledboolean | undefinedno
errorReactNodeno
hintReactNodeno
idstring | undefinedno
lengthnumber | undefinedno
namestring | undefinedno
onChange((value: string) => void) | undefinedno
onComplete((value: string) => void) | undefinedno
requiredboolean | undefinedno
valuestring | undefinedno

Proof

Contrast

measured on 0.2.0

StateForegroundBackgroundRatioFloor
defaultrgb(67 77 86)rgb(248 245 240)7.93AA 4.5
default (dark)rgb(181 182 182)rgb(7 21 34)9.07AA 4.5

Keyboard

measured on 0.2.0

KeyAction
1234Enter verification digits and advance focus
ArrowLeftFocus previous digit
ArrowRightFocus next digit
BackspaceDelete current digit

Size

16593 gzip bytes · measured on 0.2.0

Example

import { OneTimeCode } from "@/components/ui/_kit/forms/one-time-code/OneTimeCode";

const Example = () => (
		<OneTimeCode
			label="Verification code"
			length={6}
			hint="Enter the six-digit code. You can paste it here."
		/>
	);
export default Example;

not on native yet