Integrated ResearchPicasso
Components

Otp

A one-time code, entered as one field behind a row of boxes.

{/* Generated by scripts/build-component-docs.mjs — do not edit. The source is the component folder: guidance.json, the doc block and the props. Change those. */}

A one-time code, entered as one field behind a row of boxes.

Import

import { OtpInput, OtpSlot, OtpSeparator } from "@ir/ui";

Watch out

  • No caret. Figma draws the active slot empty, with the ring and the focused border as the only marker, so that is what this renders — input-otp offers a fake caret and it is deliberately not used. The ring is strong enough to place you, but a blinking caret is the more usual signal and worth a decision.

Variants

AxisOptionsDefault
sizesm · md · lgmd
activetrue · false—
invalidtrue · false—

Props

PropTypeRequiredWhat it does
sizeOtpSizeShadows the DOM size attribute, which on an <input> is a character count and means nothing here — the boxes are separate elements. Omitted from the underlying props rather than renamed, so the Figma axis keeps its name.
invalidbooleanMirrors the field family: sets aria-invalid as well as the treatment.

Do and don't

Keep the single field this component is built on.

Don't — Build the row as one input per digit.

Six inputs are six tab stops, six paste targets and a pile of focus-shuffling code — and screen readers announce six unlabelled boxes instead of one code.

Accept a pasted code and spread it across the slots.

Don't — Block paste to keep the boxes tidy.

The code arrives in another app. Pasting is how almost everyone enters it, and blocking it makes people retype from memory.

Say what went wrong and offer a resend.

Don't — Turn the boxes red and stop there.

A wrong code is usually an expired one. Without a resend the only option is to start the whole flow again.

Name the destination — "sent to •••• 4821".

Don't — Ask for the code with no context.

People check the wrong device otherwise, and there is no way to tell a delayed code from one sent somewhere they cannot reach.

Show them.

Don't — Mask the digits.

A one-time code is short-lived and is being copied from another screen. Masking it removes the only way to check it was typed correctly.

Use md below about 420 of column.

Don't — Use size="lg" on a phone.

Six lg slots are 56 each with an 8 gap, so the row needs 376 before any page padding — measured at 376 against a 360 column. md is 48 and fits at 328. The slots do not shrink on purpose: a code you cannot read is worse than one you have to scroll to.

Drop to sm below md.

Don't — Keep md on a phone and let the row scroll or spill.

Six md boxes are 352 wide with their separator and gaps, and a 360 phone leaves 328 after its gutters. sm is 304. A code is checked against another screen while it is typed, so a row that scrolls hides the digits being compared.

Accessibility

  • Active is a data state rather than :focus-visible, because the real focus lives on a single hidden input while the visible slot that should look active is a different element.
  • invalid sets aria-invalid on the input as well as the treatment, so the error reaches assistive technology and not only the eye.
  • A disabled field has no active slot at all — there is nothing to point at when nothing is editable.
  • The caret is aria-hidden. Position is conveyed by the input's own selection, not by the drawn bar.

Where it is drawn

Figma — structure from figma, measurements from figma.

Open in Storybook

On this page