Repository navigation
Description
What: useFocusTrap — Traps focus within a container element following the WAI-ARIA dialog focus-trap pattern, and restores focus when it deactivates.
A good example shows: A custom "Quick edit" side panel (not built on Dialog) with a few fields and Save/Cancel. While open, Tab and Shift+Tab cycle inside the panel, focus starts on the first field, and closing returns focus to the button that opened it.
Where:
- Hook source:
packages/core/src/hooks/useFocusTrap.ts - Hook doc:
packages/core/src/hooks/useFocusTrap.doc.mjs - Example blocks:
packages/cli/assets/templates/blocks/components/(add a<Name>.tsx+<Name>.doc.mjspair, for example underHooks/). Existing hook examples to copy the shape from:Theme/useThemeHookUsageandPopover/PopoverHookUsage.
Acceptance criteria:
-
A template block names
useFocusTrapinexampleFor(oralsoExampleFor) and renders in the Examples section of the hook's docsite page. -
The hook visibly drives the behavior: removing the hook call breaks what the example shows. Minimal code; no unrelated UI or styling.
-
Meets the rule
architecture:knowledge-contractsINV28 (docs/architecture/knowledge-contracts.md), quoted here:INV28 — Every public hook has a minimal, runnable example that
demonstrates it. A public hook is a hook that a package's committed API
report lists. Its documentation includes at least one realistic, runnable
example: a live template block that names the hook as its example target
(exampleFor, oralsoExampleForwhen the block also serves another page).
The example:- shows the hook inside a component solving the use case its docs state;
- imports the package's own code only through its public entry points;
- covers the hook's main parameters and return values;
- passes the docs build;
- gets its visible behavior from the hook itself, so removing the hook breaks
what the example shows; and - is minimal: only the code needed to show the use case, with no unrelated UI
or styling.
How a docs page selects and orders its example blocks belongs to
architecture:template-authoring. A public hook without a conforming example
is a docs gap, tracked as an issue in the repository's issue queue (DEC-16).
Good first issue: start with CONTRIBUTING.md. For orientation, run astryx docs and astryx component --list from the repo root (the CLI is node packages/cli/clients/cli/bin/astryx.mjs). The hook's own tests next to its source show how it is called.
Filed by an AI agent on behalf of the maintainer, as part of a docs-coverage sweep.
Activity
docs(useFocusTrap): add a quick edit panel example block
docs(useFocusTrap): add a quick edit panel example block (meta#9513)