Repository navigation
docs(useFocusTrap): add a quick edit panel example block - #9513
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
There was a problem hiding this comment.
The example covers what INV28 asks of a hook example and behaves as described in Chromium, but two things are needed before merge:
- Add a short comment above the
useEffectthat callsfocusFirst()saying it must run after commit, once the panel exists anduseFocusTraphas recorded the opener; a callback ref would run too early, and focus would not return after close. - Check the failed docs deploy for this commit, then fix the cause or redeploy until it passes.
[Automated review]
| onEscape: close, | ||
| }); | ||
|
|
||
| useEffect(() => { |
There was a problem hiding this comment.
This Effect is the right place for focusFirst(), but it needs a comment saying why. The panel exists only after commit, and by then useFocusTrap has recorded the opener for focus return. A callback ref looks simpler, but it runs before that record, so after Escape focus lands on <body>. For example:
// Focus moves into the panel after commit, when the panel exists.
// By then useFocusTrap has recorded the opener, so closing returns focus to it.
// A callback ref runs before that record, and focus then drops to the body.A custom quick-edit panel, not built on Dialog, traps focus with useFocusTrap: focusFirst moves focus to its field on open, Tab and Shift+Tab stay inside it, Escape closes it through onEscape, and closing returns focus to the Quick edit button. Fixes meta#9485
… of templates, and say why focusFirst runs in an effect
5e0a7c4 to
b3f4f41
Compare
PR Analysis Report🔎 Preview ·
|
There was a problem hiding this comment.
This looks ready to merge: the Quick edit panel gives useFocusTrap the runnable example that architecture:knowledge-contracts INV28 asks for, and its behavior comes from the hook itself.
- The comment above the
focusFirst()Effect, asked for in the earlier review, is in place and says why it runs after commit. - The repository's CI jobs have not run on this commit yet; they start once a maintainer adds the
ci:runlabel.
[Automated review]
Main gained meta#9509's useAnnounce example beside this one; both route manifests keep both entries.
The new example block matches `astryx search close`, so the match count goes from 46 to 47; the top 20 results are unchanged. Co-authored-by: Cindy Zhang <[email protected]>
There was a problem hiding this comment.
This looks ready to merge: the Quick edit panel gives useFocusTrap the runnable example that architecture:knowledge-contracts INV28 asks for, and its focus behavior comes from the hook itself.
- The
search closegolden count now includes the new block. - Some CI test jobs had not finished yet; confirm they pass before merging.
[Automated review]
Reader impact
A builder reading the
useFocusTrapdocs has no runnable example of the hook. After this change the hook's page shows a custom quick-edit panel, not built on Dialog, that traps focus, andastryx template useFocusTrapHookUsage <path>copies it.Source of truth
useFocusTrapand its HookDoc (packages/core/src/hooks/useFocusTrap.ts,useFocusTrap.doc.mjs).architecture:knowledge-contractsINV28.Correction
Adds
blocks/components/Hooks/useFocusTrapHookUsage(exampleFor: 'useFocusTrap'). A Quick edit button opens a Card panel (role="dialog",aria-label="Quick edit") with a Title field and Cancel/Save. The panel spreadscontainerReffromuseFocusTrap({isActive: isOpen, onEscape: close})and callsfocusFirstin an effect on open, as in the hook's JSDoc example. Closing deactivates the trap, which returns focus to the Quick edit button.Evidence
/components/useFocusTrap). Opening focuses the Title input. Tab moves Cancel, Save, then back to Title. Shift+Tab from Title goes to Save. Escape closes the panel and focus is on Quick edit.packages/cli/api/template/use-focus-trap-hook-usage.test.tsx, outsideassets/templates/so the template viewer does not load it as a template). Opening moves focus into the panel, and Escape and Cancel both close it with focus back on Quick edit. With the hook replaced by a plain ref, all three fail.focusFirstpicks. In the CLI project's jsdom,querySelectorAllwith the focusable selector list returns matches grouped by selector rather than in document order, sofocusFirstlands on Cancel there. In Chromium it lands on the input, as above.Scope
internal/shadcn-registry/routes.lock.jsonand its sandbox route inapps/sandbox/scripts/next-export-routes.json.Testing
vitest run --project node packages/cli/api/template/use-focus-trap-hook-usage.test.tsx apps/sandbox/src/route-manifest.test.ts: 9 passed, 0 failed.vitest run --project node packages/cli/foundation/discovery packages/cli/api/template packages/cli/assets/templates internal/shadcn-registry: 1105 passed, 0 failed.apps/docsite:node scripts/generate-data.mjs, thenvitest run src/__tests__/data-extraction.test.ts src/__tests__/example-coverage.test.ts: 133 passed, 0 failed. The route lock check is clean afterUPDATE_SHADCN_ROUTE_LOCK=1added the new route.pnpm -F @astryxdesign/cli typecheck(template docs and strict): clean.eslint(strict tier) andprettier --checkon the touched files: clean.pnpm lint:strictrepo-wide: 0 errors (106 warnings, none in these files).node scripts/release/changeset-coverage.mjs pr --base upstream/main --head HEAD --released v0.7.5: passes. Changeset is@astryxdesign/clipatch,[docs].pnpm testsuite.Fixes #9485