Input OTP
A one-time code in separate cells, with paste and SMS autofill.
We sent a 6-digit code to (•••) •••-4821
Installation
npm i @uisatin/uiimport { InputOTP } from '@uisatin/ui/input-otp'About 18.1 kB of JavaScript, minified and gzipped, with what it imports (React aside). The stylesheet is one file for every component.
npx shadcn@latest add https://uisatin.dev/r/input-otp.jsonAdds input-otp.tsx, button.tsx, dropdown.tsx, form-field.tsx, kbd.tsx, labels.tsx, pointer-modality.tsx, select.tsx and spinner.tsx to components/ui and installs iconoir-react.
First time with Satin? Set it up once, styles and fonts included, with the installation guide.
API Reference
The InputOTP component renders one input with autocomplete="one-time-code" over the cells, so typing, paste and SMS autofill work as in any field. onResend adds "Didn’t get it?" with a resend that opens after a countdown; suggestion offers a code that arrived by text in a popover under the cells.
| Prop | Type | Default |
|---|---|---|
length | number | 6 |
groupSize | number | 3 |
value | string | — |
defaultValue | string | — |
onValueChange | (value: string) => void | — |
onComplete | (value: string) => void | — |
pattern | RegExp | /^\d$/ |
label | ReactNode | — |
hint | ReactNode | — |
error | ReactNodeboolean | — |
success | ReactNodeboolean | — |
onResend | () => void | Promise<unknown> | — |
resendAfter | number | 30 |
suggestion | string | — |
suggestionFrom | ReactNode | "From Messages" |
disabled | boolean | — |
name | string | — |
autoFocus | boolean | — |
className | string | — |
ref | Ref<HTMLInputElement> | — |
...props | ComponentProps<'input'>Other attributes go to <input> | — |
Accessibility
One real input over the cells, with autocomplete="one-time-code" and a numeric keyboard for digits, so screen readers hear one text box and paste and SMS autofill work. Name it with label or aria-label. The cells, dashes and caret are hidden. The cell taking the next character shows the focus; a full field shows it on its last cell only when the keyboard tabs into it, so filling in the code doesn’t leave a ring behind. The message under the cells is a polite live region, so a hint changing to "Checking…", success or an error is read out; an error also sets aria-invalid. The resend countdown is plain text, so it isn’t read out every second; when it ends it becomes a "Resend code" button. A suggested code is announced once ("Code 428 193 received") and is a button right after the field, named "Use code 428 193 From Messages"; choosing it fills the field and leaves the focus there.
| Key | Action |
|---|---|
| Backspace | Deletes the last character. The caret always stays at the end. |
| Tab | From the field, moves to the suggested code, then to Resend code once it’s open. |
| Esc | Puts the suggested code away until a different one arrives. |
Something wrong or missing on this page?
Report a problemSuggest an improvement