4.2.0
Core

InputOTP

One hidden input behind a row of boxes, so a short code pastes, autofills and corrects as the single value it actually is.

InputOTP

One hidden input behind six boxes. The boxes are divs that read the engine's state, which is why the caret is drawn rather than native — and why paste, autofill and the `one-time-code` autocomplete hint all still work without a per-box handler.

Sent to the number ending 04. 6 digits to go.

Usage

import {
  InputOTP,
  InputOTPGroup,
  InputOTPSeparator,
  InputOTPSlot,
} from '@oceanic-hub/brand-system'
<InputOTP maxLength={…}>
  <InputOTPGroup>
    <InputOTPSlot index={…}>…</InputOTPSlot>
  </InputOTPGroup>
  <InputOTPSeparator>…</InputOTPSeparator>
</InputOTP>

Composition

Use the following composition to build an InputOTP:

InputOTP
├── InputOTPGroup ×2
│   └── InputOTPSlot ×6
└── InputOTPSeparator

Reach for it when the value is a short, fixed-length code the reader is copying from somewhere else — an SMS or authenticator code, a workspace invite, a device PIN. The boxes are what make it worth the extra component: they show how much is left to type without a character count, and they make a mistyped digit findable. If the length is not fixed, or the reader is recalling the value rather than transcribing it, that is an Input.

There is exactly one <input>, and none of the boxes is it. The root renders a single visually hidden field stretched across the row; the slots are divs that read the engine's state and paint it. Three things follow, and all three surprise people:

  • Everything that belongs to the field goes on the ROOT — disabled, aria-invalid, id, autoFocus. Putting them on a slot styles nothing and tells assistive technology nothing.
  • Anything you want a box to look like is composition, on the slot's className. The one exception is validity: a slot is a div with no role, so it reads the root's aria-invalid — and a wrapping Field's data-invalid — itself, and every box turns stuck together (@OCE-1877). Saying it once on the root is now enough; it used to take a hand-written border on all six.
  • Paste, autofill and the one-time-code keyboard hint are the engine's, not ours, and they already work. A hand-rolled per-box paste handler is the classic bug in this control, and not writing one is the reason to take the dependency at all.

pattern decides which keystrokes the engine accepts; pasteTransformer decides what a paste that does not match becomes, which is how "Your code is 482 193" still lands as six digits. The engine's REGEXP_ONLY_DIGITS family of constants is deliberately not re-exported — they are strings belonging to input-otp, not brand surface — so write the expression yourself, or import them from input-otp directly.

There is a second route in, render, where the engine hands you the slot array and you draw it. It works, and nothing in this package styles its output: the documented route is children, because that is the one the slot's four states were painted for.

RTL is not supported. Upstream ships an RTL example and answers direction with a global configuration guide; we have none, because nothing in this package has ever been laid out or measured right-to-left, and a code that reads backwards is worse than one that refuses.

Upstream's separate Separator and Controlled examples are folded into the default demo above, which is both — a controlled six-digit code in two groups with a separator between them.

Digits only

pattern is what the engine will accept a keystroke for; pasteTransformer is what it does with a paste that does not match — here, strip everything that is not a digit so pasting the whole SMS still fills the boxes. The engine's own REGEXP_ONLY_DIGITS constant is deliberately not re-exported: write the expression, or import it from input-otp yourself.

4
8
2
1

Pasting “Your code is 482 193” leaves 482193 in the boxes.

Alphanumeric

Widen pattern when the code is not a number — an invite, a licence key, a recovery code. maxLength decides how many slots have anything to read, so eight of them here, split into two groups short enough to read aloud in one go.

Workspace invite code
7
Q
F
2

Disabled

disabled goes on the root, and the whole row fades to 40% together from the container — the same treatment every other control in the package uses. Reach for it while the code is still on its way, so the boxes hold their place instead of appearing under the reader's cursor; it is also the one state an interactive demo can never show you by itself.

2
0

Invalid

A rejected code is aria-invalid on the root, and the root is the only real input — so that is both where assistive technology reads it and the one place it has to be said. Every slot reads it and turns stuck together. The border says something is wrong; FieldError says what.

4
8
2
1
9
3

Four digits

maxLength is the only thing that changes for a shorter code. Four is short enough to hold in one go, so it takes a single group and no separator — the grouping exists to break a long code into chunks a person can carry from their phone to the keyboard, and four digits are already one chunk.

3
1
7
2

In a form

onChange hands you the string, not a change event, so a FormField wires straight to it with no adapter. onComplete fires the instant the last box fills — submit on it when the code is the only thing you are asking for, and keep the button as the way back for anyone who pastes, corrects a digit, or never triggers it.

Sent to the number ending 04.

API Reference

See the InputOTP API page for every prop of every part, with types, defaults and the contract that pins them.

On this page