# One-time code

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

## Web 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.

```json
{
  "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.

```sh
npx shadcn@latest add @maeso/maeso
```

```css
@import "./styles/theme.web.css";
```

```sh
npx shadcn@latest add @maeso/one-time-code
```

### Props

#### OneTimeCode

| Prop | Type | Required | Description |
| --- | --- | --- | --- |
| label | ReactNode | yes |  |
| defaultValue | string \| undefined | no |  |
| disabled | boolean \| undefined | no |  |
| error | ReactNode | no |  |
| hint | ReactNode | no |  |
| id | string \| undefined | no |  |
| length | number \| undefined | no |  |
| name | string \| undefined | no |  |
| onChange | ((value: string) => void) \| undefined | no |  |
| onComplete | ((value: string) => void) \| undefined | no |  |
| required | boolean \| undefined | no |  |
| value | string \| undefined | no |  |

### Proof

#### Contrast

measured on 0.2.0

| State | Foreground | Background | Ratio | Floor |
| --- | --- | --- | --- | --- |
| default | rgb(67 77 86) | rgb(248 245 240) | 7.93 | AA 4.5 |
| default (dark) | rgb(181 182 182) | rgb(7 21 34) | 9.07 | AA 4.5 |

#### Keyboard

measured on 0.2.0

| Key | Action |
| --- | --- |
| 1234 | Enter verification digits and advance focus |
| ArrowLeft | Focus previous digit |
| ArrowRight | Focus next digit |
| Backspace | Delete current digit |

#### Size

16593 gzip bytes · measured on 0.2.0

### Example

```tsx
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;
```

### Preview · 0.2.0

not on native yet
