Inputs · OTPInputstable
OTP input
Enter a short one-time code, one character per slot. One real input behind square, bordered slots; 4 or 6 characters with an optional 3 + 3 separator.
Preview
#previewSwitch length, separator, validation and state. Show code opens the React and CSS below.
maxLength 6 · separator · helpText
verify-code.tsx
import { OTPInput } from "@blade-ai/weft/components/otp-input";
export function VerifyCode({ error, isVerifying, onVerify }: Props) {
return (
<OTPInput
label="Verification code"
maxLength={6}
separator
onComplete={onVerify} // verify here, no Submit button
validationState={error ? "error" : "none"}
helpText="Sent to +91 98•••• 210 · Resend in 0:24"
errorText={error}
/>
);
}All states
#all-statesEvery state from the OTP Input spec, named and shown at the single size (36px slots).
Default · empty
Hover
Focus-visible · active slot
Typing · partially filled
Pasted / auto-filled
Complete
Loading · verifying
Success
Error
Disabled
Read-only
Props
#propsBooleans are is-prefixed. label is required. Anything marked UNDEFINED is an open decision.
Prop
Type
Default
Description
label *
string
—
Visible label above the slots. Required for accessibility.
maxLength
4 | 6
6
Number of slots. Codes over 8 characters use Text Input.
pattern
string (RegExp source)
"REGEXP_ONLY_DIGITS"
Allowed characters. REGEXP_ONLY_DIGITS or REGEXP_ONLY_DIGITS_AND_CHARS, both exported from the component.
value · defaultValue
string
—
Controlled or uncontrolled value, 0 to maxLength characters matching pattern. Pair value with onChange.
onChange
(value: string) => void
—
Fires with the new value.
onComplete
(value: string) => void
—
Fires once when the last slot fills. Verify here; no Submit button.
separator
boolean
false
Splits 6 slots into 3 + 3. Ignored unless maxLength is 6.
validationState
"none" | "error" | "success"
"none"
error sets aria-invalid="true".
helpText
ReactNode
—
Masked destination and resend timer, e.g. "Sent to +91 98•••• 210 · Resend in 0:24".
errorText
ReactNode
—
Shown instead of helpText when validationState="error", prefixed "! ".
successText
ReactNode
—
Shown instead of helpText when validationState="success", prefixed "✓ ". Prop name: UNDEFINED.
necessityIndicator
"none" | "required" | "optional"
"none"
Marks the field required (*) or optional in the label.
isDisabled
boolean
false
Disables the input; opacity 50% on the whole field.
isReadOnly
boolean
false
Read-only look: UNDEFINED. Drawn with filled tokens and no caret.
isLoading
boolean
false
Verifying after onComplete. Input is read-only with aria-busy; spinner after the slots.
Usage
#usageShort rules for building code-entry fields.
Do
Use maxLength 4 or 6; split 6 into 3 + 3 only when separator is true.
Set autocomplete="one-time-code" and inputMode="numeric" on the single input (the component does).
Verify inside onComplete and show isLoading until the result returns.
Put the masked destination and resend timer in helpText.
Keep the digits on error and say what to do: "That code is incorrect".
Don't
Build the field from separate Text Inputs.
Use OTP Input for codes over 8 characters, PINs or coupons.
Block paste or autofill.
Add a Submit button for the code.
Add radius, gaps between slots or colours that are not in the states table.
Build anything marked UNDEFINED until it has a decision.
Accessibility
#accessibilityOne real input behind presentational slots; paste and autofill fill every slot at once.
Keyboard
Key
Action
0-9
Types into the active slot and moves to the next one.
Backspace
Clears the current slot and moves to the previous one.
← / →
Moves between slots.
Cmd / Ctrl + V
Pastes the whole code.
Tab
Leaves the code input.
Shift + Tab
Leaves the code input backwards.
Enter
Native form submit. No extra behaviour; verification runs from onComplete.
ARIA
Element
Role / attribute
When
<input>
native textbox · id linked from <label htmlFor>
Always
<input>
aria-describedby="{messageId}"
Help or error text is shown
<input>
aria-invalid="true"
validationState = "error"
<input>
aria-busy="true" · readOnly
isLoading
<input>
aria-required="true" · disabled
necessityIndicator = "required" · isDisabled
slot
presentational · aria-hidden="true"
Always
separator
role="separator"
separator = true
spinner <svg>
aria-hidden="true"
isLoading
resend countdown
aria-live="polite"
Announce when resend becomes available, not every second (consumer-rendered)
Agent Spec
#agent-specMachine-readable spec, tables (a)–(h). Same source as /specs/otp-input.json. Anything marked UNDEFINED needs a decision before it is built.
[ "Caret blink", "Autofill highlight", "Pressed token for a slot", "Slot success border and background", "Read-only look (no tokens)", "Resend control (Link vs Button) and timer length", "labelPosition=\"left\" for OTP (not built)", "Other sizes (small, large, mobile 40px)", "successText prop name", "\"(optional)\" label wording for necessityIndicator=\"optional\"" ]