FocusRecovery Atom
Return focus to an injected section heading when a focused control disappears. The application chooses the destination and when its content is ready; the primitive preserves intentional focus elsewhere. A connected Modal or Drawer opener keeps ordinary return focus.
Usage
Use a stable heading ref and tabIndex={-1} to make the destination programmatically focusable
without adding a Tab stop. Heading forwards both props to its existing semantic heading.
Entries
Activate “Remove entry” with the keyboard. The heading becomes the focus destination; the next Tab continues through this section. Failed operations that leave the control mounted keep its focus.
FocusRecovery observes removals inside its own DOM root, which uses display: contents to
preserve layout. It adds no landmark or keyboard shortcut. Portalled Modal/Drawer content inherits
the recovery destination through context, but its focus is not treated as list focus.
Nested recovery sections own their descendants: an ancestor cannot recover a nested section's
control while that section is still loading.
Props
| Prop | Type | Default | Notes |
|---|---|---|---|
| targetRef | RefObject<HTMLElement | null> | — | A connected, programmatically focusable heading or control chosen by the application. |
| ready | boolean | true | Wait for related content before completing a pending recovery. |
| children | ReactNode | — | The controls and overlays belonging to this task. |
Do
Choose one stable destination in the same task and wait for its read to settle.
Don't
Use recovery to move focus away from an active overlay or a control the user intentionally chose.
Keyboard
- Ordinary controls retain their existing keyboard contract.
- A removed focused control returns focus to the injected target when
ready. - Recovery permits the browser to scroll the destination into view.
- A connected overlay opener wins over the fallback; disabling overlay return focus also disables its fallback.
- Recovery never adds the heading to the ordinary Tab order or overrides intentional focus elsewhere.
Tokens
The recovery wrapper has no visual treatment. Opt-in Heading focus outlines use
--cb-focus-width, --cb-focus-offset, and --cb-tone-brand.