Repository navigation
fix(Drawer): a non-modal drawer that unmounts while open returns focus to its opener - #9672
Conversation
…pener Drawer FR8 (Specs ruling for #8963, same as Dialog): when an open Drawer unmounts, it returns focus to the captured element if focus would otherwise be lost. The check runs after the commit, so StrictMode's simulated unmount and a hidden Activity, which keep the drawer in the document, leave focus alone. Tests cover modal and non-modal, removal by its own control and with its view, focus moved outside first, and StrictMode; a Chromium spec covers click and Enter on the UnmountWhileOpen story.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report🔎 Preview ·
|
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| Drawer | 50.7 kB (+41 B) · 8.3 kB CSS (0) | — | ✓ · ✓ · ✓ |
| DrawerHeader | 63.4 kB (0) · 12.9 kB CSS (0) | — | ✓ · ✓ · ✓ |
Package size: @astryxdesign/core 7.18 MB packed (+248 B); no new dependencies.
API changes: none in this pull request
Committed API report behind this build: cli 29 rows, core 34 rows, theme-butter 1 row, theme-y2k 1 row; run pnpm api:report.
Touched components checked; add ci:run-visual or ci:run-rtl to run the full suites.
Generated by PR Enrichment workflow | View full report
|
AI review status for this pull request.
|
|
/approve-spec ba74f3e |
There was a problem hiding this comment.
Requesting changes: the unmount focus return does not run in a real browser for the drawers it targets.
- The new
returnFocusAfterRemovalcall sits inside theisDrawerHostOpencheck (useDrawerDialogPresence.ts:182-188), which is already false once a non-modal (popover) drawer has been removed, so in Chromium theUnmountWhileOpenstory still leaves focus on the page body after Save (click or Enter), and moving the call below the check fixes it. - The non-modal jsdom cases pass only because the test's
showPopovermock setsopen, which jsdom never clears on removal, so they need a mock that models removal, and the Chromium spec (skipped on this draft) needs to run green. returnFocusAfterRemovalrepeats the restoreuseFocusTrapalready runs for modal drawers (useFocusTrap.ts:297-341), so please extend that shared restore so both presentations make one call, and drop the local copy.- The changeset and title say any drawer is fixed, but a modal drawer already returned focus on
main(as #8963 notes), so the wording should name non-modal drawers (hasScrim={false}).
The FR8 sentence itself is approved for this head. A non-blocking suggestion on the new doc comment is inline.
[Automated review]
…res the focus trap's rule CodeBunny on #9672: removal already hid a popover host, so the call inside the host-open check never ran for a non-modal drawer in a browser. It now runs outside it. returnFocusIfLost in utils/focusReturn is the restore useFocusTrap ran on deactivation; the trap and the drawer's unmount both call it. The unmount tests model popover removal, so they fail with the old placement. The changeset names non-modal drawers; a modal drawer already returned focus through its trap.
|
/approve-spec 6edf3ac |
There was a problem hiding this comment.
Approve: a non-modal Drawer (hasScrim={false}) removed while open now returns focus to the control that opened it, and the points from the previous review are addressed.
- The removal check now runs for popover drawers, and the new
DrawerUnmountFocus.a11y.chromium.spec.tscovers click and Enter on theUnmountWhileOpenstory. - Non-blocking:
mainhas since addedcomponent:DrawerFR19 and a new import inuseDrawerDialogPresence.ts, which conflict with this branch, so keep both when you rebase.
[Automated review]
…-unmount-focus # Conflicts: # docs/specs/components/Drawer/Drawer.spec.md # packages/core/src/Drawer/Drawer.test.tsx # packages/core/src/Drawer/useDrawerDialogPresence.ts # packages/core/src/hooks/useFocusTrap.ts
…11y-spec wrapper Every Playwright browser context stays off remote hosts through the wrapper, which the lint rule now requires.
There was a problem hiding this comment.
Approval waits on an engineering owner's decision on the new Drawer FR8 sentence, and two fixes are needed.
- FR8 now says "When an open Drawer unmounts, it MUST return focus to the captured element if focus would otherwise be lost…". This is new spec text, and the earlier
/approve-speccomments name older commits. An engineering owner records the decision by commenting/approve-spec 5f20da09f12fe8ea2b8c22d14aff78a01aa6a0cc; the author may do so as an engineering owner.
Blocking:
- Regression: when
Drawer.test.tsxruns as a whole file, "returns focus to the opener (non-modal, save)" fails withRangeError: Maximum call stack size exceeded, because the keyboard-open test merged frommainleaves itsElement.prototype.matchesspy in place; addingvi.restoreAllMocks()to the file-levelafterEachfixes it. - Regression:
returnFocusAfterRemovalinuseDrawerDialogPresence.tscopies the removal focus repair thatprepareFocusReturnOnRemovalinutils/focusReturn.tsnow provides for Dialog and Lightbox; call that helper from the unmount cleanup and delete the copy.
The fix itself works: in Chromium, focus now returns to the opener after Save, by click or Enter.
[Automated review]
Main's keyboard-open test also replaces matches, so reading it in beforeEach could capture this suite's own stand-in, which then called itself. The suite now reads the native method at collection.
|
/approve-spec c6e3050 |
There was a problem hiding this comment.
Changes requested: the non-modal unmount focus return works, and the new FR8 sentence is approved for this head, but the removal repair should reuse the shared helper.
- Regression:
returnFocusAfterRemovalinpackages/core/src/Drawer/useDrawerDialogPresence.ts(lines 221-233) re-implements the removal focus repair thatprepareFocusReturnOnRemovalinpackages/core/src/utils/focusReturn.tsalready provides for Dialog and Lightbox, so create that repair in the unmount effect, call it from the cleanup with the captured trigger, and delete the copy.
In Chromium, focus now lands on "Edit row" after Save by click or Enter, and the new non-modal tests fail without the fix and pass with it. With the shared helper in its place, the whole Drawer suite still passes.
[Automated review]
prepareFocusReturnOnRemoval already returns focus to an opener when Dialog or Lightbox leaves the document. The drawer now calls it, and its own copy and the focus-trap refactor it needed are gone.
|
/approve-spec 5c32b9c |
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet because the pull request is a draft; it runs once the pull request is marked ready for review.
A non-modal Drawer removed while it is open now returns focus to its opener through the shared removal repair, and the new tests fail without the fix and pass with it. The earlier request to reuse that shared repair is addressed.
- Non-blocking: the description's "Smallest restoration" and "Evidence" sections still mention a
returnFocusIfLosthelper and auseFocusTrapchange that this head no longer contains; please update them.
[Automated review]
failingSpecs no longer waits after its fourth and last try, so a log that keeps answering 5xx gives up after 30 s of waits, and a test pins four server errors in a row. This also corrects the earlier commit's wording: the three pull requests that now replay a narrow selection (#9672, #10271, #10944) are ones whose story was their only full-suite trigger, not ones that change only stories. Their stories are Drawer, TableSelection and Avatar; Button's specs run because those stories import Button.
… retries a server error (#11317) * ci: the selection replay record covers the story rule; a log download retries a server error The record is regenerated with the Chromium lane's story rule (#11250). Every verdict matches the earlier record: 144 no failure, 4 caught, 4 reviewed, 1 out of scope. Three pull requests that change only stories now replay a narrow selection with no failure (#9672, #10271, #10944). GitHub's job-log endpoint answers 502 now and then, so failingSpecs tries a server error again, up to four times, before it calls a log unreadable. * Merge remote-tracking branch 'origin/main' into ci/replay-story-rule * ci: a log download waits only between tries, not after the last failingSpecs no longer waits after its fourth and last try, so a log that keeps answering 5xx gives up after 30 s of waits, and a test pins four server errors in a row. This also corrects the earlier commit's wording: the three pull requests that now replay a narrow selection (#9672, #10271, #10944) are ones whose story was their only full-suite trigger, not ones that change only stories. Their stories are Drawer, TableSelection and Avatar; Button's specs run because those stories import Button.
Part of #8963 (Drawer; Dialog is #9627 and Lightbox is #9629).
User impact
A non-modal
Drawer(hasScrim={false}) that unmounts while it is still open drops focus to the page body instead of returning it to the control that opened it. Keyboard and screen-reader users meet this in two common React patterns:{isEditing && <Drawer isOpen …>}), whose own Save button removes it.They then have to find their place again from the top of the page. A close through
onOpenChangealready returns focus, and so does a modal drawer's focus trap on unmount, so only the non-modal unmount drops it.Problem and solution fit
<dialog>doesn't run the browser's own focus return, so focus inside the drawer falls to the body.useDrawerDialogPresenceleft the native host and fired the owedcloseevent, but it said "no focus restore on this path". A modal drawer is covered byuseFocusTrap's restore, but a non-modal drawer has no trap.Expected behavior and authority
component:DrawerFR8 gains the sentence the Specs ruling for [Bug] Dialog, Lightbox, BottomSheet, Drawer: unmounting while open drops focus to the body #8963 asked for, the same rule as Dialog: "When an open Drawer unmounts, it MUST return focus to the captured element if focus would otherwise be lost (left on the page body or on a node that left the document); a development-only simulated unmount is not a removal."Smallest restoration
returnFocusIfLost(surface, target)inutils/focusReturn.tsis the ruleuseFocusTrapalready ran on deactivation. It focuses the target only when focus would be lost (isFocusLost) and the target is still in the document.useFocusTrapnow calls it, so its behavior is unchanged.<Activity>keep the drawer in the document, so they leave focus alone.closeordering, and the modal host don't change.Evidence
Drawer.test.tsxcases ("Drawer unmounting while open") fail on the base. Their popover stand-ins model the browser: a removed popover host is no longer:popover-open, and a non-modal drawer sets noopenattribute. With the call inside the old "host still open" check, they fail too.DrawerUnmountFocus.a11y.chromium.spec.tsruns on the newUnmountWhileOpenstory in Chromium. Open "Edit row", then click Save, or press Enter on it. The drawer is gone and "Edit row" has focus.Scope
Testing
pnpm vitest run packages/core/src/Drawer: 91 passed.pnpm check:knowledge: aligned.Writing rubric results
Run over the new Drawer FR8 sentence and its verification row: