OTP input
OTP input component for verification codes with auto advance, paste and autofill support, masking and validation states.
How to use it
Run npx @blossomui/react add otp-input, or copy src/components/UI/OtpInput/OtpInput.tsx into your React project and import it.
import { OtpInput } from './components/ui/OtpInput'Props
OtpInputProps
| Prop | Type | Description |
|---|---|---|
| length | number | Number of boxes. |
| value | string | Controlled value. Use together with `onChange`. |
| defaultValue | string | Initial value when the component is not controlled. |
| onChange | (value: string) => void | Called every time a character is typed, deleted or pasted. |
| onComplete | (value: string) => void | Called once, when every box is filled. |
| type | 'numeric' | 'alphanumeric' | `numeric` accepts digits and opens the numeric keyboard on a phone, `alphanumeric` also accepts letters. |
| mask | boolean | Hide the characters, like a password. |
| separatorAfter | number[] | Draws a dash after these boxes, for example `[3]` shows 123 - 456. |
| color | string | Accent color of this component: any CSS color. Without it the component uses `--blossom-accent`, which is pink by default. |
| label | string | |
| hint | string | Helper text shown under the boxes. |
| error | string | Error message. Turns the boxes red. |
| success | string | Success message. Turns the boxes green. |
| size | 'sm' | 'md' | 'lg' | |
| disabled | boolean | |
| autoFocus | boolean | Focus the first empty box when the component is shown. |
| name | string | Adds a hidden input with this name so the code is sent with native forms. |
| boxLabel | (position: number, length: number) => string | Accessible name of each box, for example "Character 2 of 6". |