Code Input

A one-time code, one 48 px box per character, over one real input so paste and the phone's code autofill work. Built on ui-sdk's OTP Input. Used for phone verification in onboarding.

BetaReady to use. Its API can still change in a minor release; the changelog says when.

import { CodeInput } from "@leap-crm/design-system";

Playground

Change a prop and the component follows. Its code is under Props.

Props

length
isInvalid
disabled

Best practices

When to use it, and the rules that apply in particular places.

GuidancePractice
DoUse it for a one-time code with a fixed length, like the SMS code that verifies a lawyer's phone in onboarding.
DoPut it in a Field with a label. The field's error turns the boxes red and is announced, so the state isn't shown by colour alone.
DoVerify in onComplete, which runs once every box is filled, typed or pasted, so nobody has to press a button after pasting the code.
DoWrite the error as what to do next, like "Please enter the code we sent you", and clear it in onChange when they start again.
Don'tUse it for a matter number, a reference or any value without a fixed length. Use Input.
Don'tBuild the boxes from separate inputs. It sits over one real input so paste and the phone's code autofill work.

Props

Also takes ui-sdk's OTP Input options: value, defaultValue, pattern (digits by default), inputMode, autoComplete, name, disabled, id and autoFocus.

PropTypeDefaultDescription
lengthnumber6How many characters the code has, one box each.
onChange(value: string) => void—Runs on every change with the code so far.
onComplete(value: string) => void—Runs once every box is filled, typed or pasted, like to verify it.
isInvalidboolean—Draws every box red, and the active one with the red ring. Inside a Field, its error does this.
classNamestring—Classes added to the root element, merged with its own. Tokens only.

Code

What the playground shows, ready to copy.

import { CodeInput } from "@leap-crm/design-system";

<CodeInput aria-label="Verification code" />

Keyboard

The keys it answers to. Tab moves between components, arrows move within them.

KeysWhat they do
TypingFills the slots in order.
BackspaceDeletes the last character.
ArrowLeftGoes back a slot; typing then replaces its character.