Pairing Code
PairingCode and PairingCodeInput for pairing a device by code (OAuth device authorization, RFC 8628). PairingCode shows a short user code big, monospaced and grouped (BCDF-GHJK), spelled out character by character for screen readers, with a copy button, and can compare it with the code on the other screen: `confirm` asks whether they match, `enter` checks a typed code group by group. PairingCodeInput is the verification page's field: it normalizes case, drops characters outside `alphabet`, inserts the separator as the person types or pastes, and calls `onComplete` once the code is full. `agentHidden` keeps the code from agents.
Example
Letters only; the dash is added for you.
Does your device show the same code?
Installation
lucide-reactUsage
Device pairing by code (RFC 8628): PairingCode on the screen that shows the user code, PairingCodeInput on the verification page that never knows it. Pass the code with or without separators; compare="confirm" or "enter" checks it against the other screen.
API reference
PairingCodeInput
| Prop | Type | Default |
|---|---|---|
labelrequiredThe field's visible label, which names it for screen readers and agents. | ReactNode | – |
lengthrequiredHow many characters a full code has. | number | – |
alphabetThe characters a code may hold, in any case; others are dropped as they're typed or pasted. Letters and digits by default. | string | – |
groupSizeCharacters per visual group; 4 by default. | number | 4 |
separatorInserted between groups as the person types; "-" by default. | string | "-" |
valueThe code, normalized, for a controlled field. | string | – |
defaultValue | string | – |
onChangeRuns with the normalized code, without separators, on every change. | (code: string) => void | – |
onCompleteRuns with the normalized code each time an edit makes it full. | (code: string) => void | – |
pendingMakes the field read-only and busy, like while the code is looked up. | boolean | false |
errorShown in a live alert under the field, which is marked invalid. | ReactNode | – |
description | ReactNode | – |
agentHiddenKeeps the field from agents: they can't read or type the code. | boolean | false |
size | "default" | "lg" | "default" |
name | string | – |
placeholder | string | – |
classNameOn the field's wrapper, like `style`. | string | – |
style | CSSProperties | – |
Also takes DataAttributes &.
PairingCode
| Prop | Type | Default |
|---|---|---|
coderequiredThe code, with or without separators, in any case. | string | – |
labelrequiredNames the code for screen readers and agents, like "Pairing code". | string | – |
groupSizeCharacters per visual group; 4 by default. | number | – |
separatorShown between groups and copied with the code; "-" by default. | string | – |
size | PairingCodeSize | – |
agentHiddenKeeps the code from agents: they can't read, copy or compare it, while a person can. | boolean | – |
onCopyRuns once the code, with separators, is on the clipboard. | (code: string) => void | – |
labels | Partial<PairingCodeLabels> | – |
id | string | – |
className | string | – |
compareAsks the person whether the code matches the one on the other screen. | undefined | "confirm" | "enter" | – |
text | undefined | PairingCodeConfirmText | PairingCodeEnterText | – |
onConfirm | (matches: boolean) => unknown | – |
onMatchChangeRuns when the typed code starts or stops matching. | (matches: boolean) => void | – |
Other exports
caretAftercomparePairingCodeGroupseditPairingCodeformatPairingCodenormalizePairingCodepairingCodeGroupspairingCodepairingCodeLabelstype PairingCodeEdittype PairingCodeFormattype PairingCodeGroupMatchtype PairingCodeComparetype PairingCodeOptionstype PairingCodeStatetype PairingCodeInputPropstype PairingCodeSizetype PairingCodeConfirmTexttype PairingCodeEnterTexttype PairingCodeLabelstype PairingCodePropsAccessibility
- The visual groups are hidden from screen readers, which hear the code spelled out a character at a time with a pause between groups (labels.spell).
- The input inserts its own separators and keeps the caret after what was typed; pending makes it read-only with aria-busy, and an error is a live alert that describes the field, which turns aria-invalid.
- In enter mode each group shows a tick, a cross or a dashed circle beside its colour, and a status line says whether the codes match.
- PairingCodeInput passes id, data-* and aria-* to its input without replacing the busy, invalid, label and description attributes the field manages; a passed aria-describedby joins the field's own.
Agent actions
Agents read code from the pairing-code component and call copy() and confirm(true | false); they type into PairingCodeInput with setValue, normalized like typing. agentHidden keeps the code, its copy button and its comparison from agents, and copy and confirm fail the step with why.
Runs agent.snapshot() from @ui-sdk/react/agent on the live preview above.