# Matrix code

A one time code on dot matrix panels that pours into a check.

Also called: otp input, otp, one time password, verification code, 2fa code, pin input.

> chatcn Pro: needs a Pro license (https://chatcn.dev/pro). Install from the `@chatcn-pro` registry with your license token; setup at https://chatcn.dev/docs/chatcn-pro.

Example: A code that pours into a check. Each digit scans onto its dot panel; the right code sends every lit dot flying into one big check, which settles beside Verified. Preview: https://chatcn.dev/preview/matrix-code-demo

Each digit lights up on its panel in a quick top down scan, and the caret is the panel's bottom row of dots, blinking with a small wipe. Get the code right and every lit dot leaves its panel on a lifted arc and pours into one big dotted check, a light runs along it, and it settles small beside Verified. Get it wrong and the dots burst out, spring back in red and clear. A real input sits underneath, so typing, pasting and one time code autofill all work.

## Installation

```bash
npx shadcn@latest add @chatcn-pro/matrix-code
```

## Usage

```tsx
import { MatrixCode } from "@/components/ui/chatcn/pro/matrix-code"

<MatrixCode verify={(code) => api.checkCode(code)} hint="Didn't get a code? Resend" />
```

`verify` can return a promise. Clear `value` after Verified to play the dots back home.

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `verify` | `(code: string) => boolean | Promise<boolean>` | Runs once every digit is in |
| `length` | `number` | Default 6, split in half |
| `value` / `onValueChange` | `string` | Optional control |
| `hint` | `ReactNode` | Under the panels |
| `invalidMessage` / `verifiedLabel` | `ReactNode` |  |

## Keyboard

| Key | Action |
| --- | --- |
| `0` to `9`, paste | Fill the code |
| `Backspace` | Clear a digit |
| `Escape` | Start again after Verified |

## Accessibility

- One real input with `autocomplete=one-time-code`; the wrong code message and Verified are announced as a status.

## Motion

- Digits scan in 110 ms; the dots fly 640 ms on a small spring and settle in 620 ms. Reduced motion: the check appears without the flight.

Source: https://chatcn.dev/docs/components/matrix-code