Repository navigation
fix(BottomSheet, Dialog): returning focus after an overlay closes no longer scrolls the page - #10022
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
/approve-spec 647f3c5 |
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| CommandPalette | 58.3 kB (+34 B) · 12.3 kB CSS (0) | — | — · — · — |
| DateRangeInput | 75.7 kB (+33 B) · 11.2 kB CSS (0) | — | — · — · — |
| AlertDialog | 89.9 kB (+31 B) · 13.1 kB CSS (0) | — | — · — · — |
64 more components
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| lab/Comments | 269.8 kB (+30 B) · 2.5 kB CSS (0) | — | — · — · — |
| MoreMenu | 77.6 kB (+29 B) · 16.1 kB CSS (0) | — | — · — · — |
| Pagination | 92.4 kB (+27 B) · 16.5 kB CSS (0) | — | — · — · — |
| Markdown | 152.3 kB (+26 B) · 18.9 kB CSS (0) | — | — · — · — |
| ContextMenuItem | 23.8 kB (+25 B) · 6.0 kB CSS (0) | — | — · — · — |
| lab/TourStep | 61.1 kB (+25 B) · 590 B CSS (0) | — | — · — · — |
| Selector | 82.3 kB (+24 B) · 16.1 kB CSS (0) | — | — · — · — |
| Tokenizer | 73.8 kB (+24 B) · 17.1 kB CSS (0) | — | — · — · — |
| lab/CommentComposer | 108.6 kB (+24 B) · 1.9 kB CSS (0) | — | — · — · — |
| lab/Schedule | 63.5 kB (+24 B) · 3.9 kB CSS (0) | — | — · — · — |
| Table | 91.2 kB (+22 B) · 16.7 kB CSS (0) | — | — · — · — |
| DateTimeInput | 176.8 kB (+21 B) · 17.2 kB CSS (0) | — | — · — · — |
| DateInput | 154.9 kB (+20 B) · 15.5 kB CSS (0) | — | — · — · — |
| Drawer | 41.0 kB (+20 B) · 8.2 kB CSS (0) | — | — · — · — |
| MultiSelector | 79.5 kB (+20 B) · 15.5 kB CSS (0) | — | — · — · — |
| lab/ChatReactionBar | 69.4 kB (+20 B) · 1.1 kB CSS (0) | — | — · — · — |
| TableCell | 83.0 kB (+19 B) · 16.5 kB CSS (0) | — | — · — · — |
| lab/ChatEmojiPicker | 68.9 kB (+19 B) · 773 B CSS (0) | — | — · — · — |
| Lightbox | 54.8 kB (+18 B) · 9.1 kB CSS (0) | — | — · — · — |
| richtext/RichTextEditorToolbar | 232.9 kB (+17 B) · 454 B CSS (0) | — | — · — · — |
| DropdownMenu | 77.4 kB (+16 B) · 16.1 kB CSS (0) | — | ✓ · ✓ · ✓ |
| TableHeaderCell | 82.6 kB (+16 B) · 16.2 kB CSS (0) | — | — · — · — |
| TimeInput | 140.4 kB (+16 B) · 14.5 kB CSS (0) | — | — · — · — |
| BottomSheet | 56.3 kB (+15 B) · 7.5 kB CSS (0) | — | ✓ · ✓ · — |
| ContextMenu | 81.8 kB (+15 B) · 16.0 kB CSS (0) | — | — · — · — |
| Dialog | 22.0 kB (+14 B) · 6.7 kB CSS (0) | — | ✓ · ✓ · — |
| PowerSearch | 249.2 kB (+14 B) · 22.3 kB CSS (0) | — | — · — · — |
| Popover | 55.1 kB (+13 B) · 12.8 kB CSS (0) | — | — · — · — |
| lab/TransferListSelector | 86.4 kB (+12 B) · 1.9 kB CSS (0) | — | — · — · — |
| BottomSheetSwitcher | 17.4 kB (+11 B) · 3.4 kB CSS (0) | — | ✓ · ✓ · — |
| lab/CommentThread | 264.6 kB (+9 B) · 2.4 kB CSS (0) | — | — · — · — |
| ChatComposerTokenElement | 61.3 kB (+2 B) · 10.0 kB CSS (0) | — | — · — · — |
| ComplexSelector | 57.6 kB (+1 B) · 10.4 kB CSS (0) | — | — · — · — |
| TopNavMenu | 60.9 kB (+1 B) · 9.9 kB CSS (0) | — | — · — · — |
| AvatarGroup | 37.7 kB (0) · 5.5 kB CSS (0) | — | — · — · — |
| BaseTypeahead | 57.1 kB (0) · 9.6 kB CSS (0) | — | — · — · — |
| BreadcrumbItem | 71.1 kB (0) · 11.2 kB CSS (0) | — | — · — · — |
| ButtonGroup | 9.1 kB (0) · 3.4 kB CSS (0) | — | — · — · — |
| ChatComposer | 63.3 kB (0) · 10.5 kB CSS (0) | — | — · — · — |
| ChatComposerInput | 61.3 kB (0) · 10.0 kB CSS (0) | — | — · — · — |
| Collapsible | 24.6 kB (0) · 4.5 kB CSS (0) | — | — · — · — |
| DialogHeader | 49.6 kB (0) · 10.2 kB CSS (0) | — | ✓ · ✓ · ✓ |
| DropdownMenuCheckboxItem | 20.7 kB (0) · 6.3 kB CSS (0) | — | ✓ · ✓ · ✓ |
| DropdownMenuDivider | 5.2 kB (0) · 548 B CSS (0) | — | ✓ · ✓ · — |
| DropdownMenuGroup | 6.3 kB (0) · 3.4 kB CSS (0) | — | ✓ · ✓ · — |
| DropdownMenuItem | 19.9 kB (0) · 5.9 kB CSS (0) | — | ✓ · ✓ · — |
| DropdownMenuRadioGroup | 6.3 kB (0) · 3.3 kB CSS (0) | — | ✓ · ✓ · — |
| DropdownMenuRadioItem | 20.7 kB (0) · 6.3 kB CSS (0) | — | ✓ · ✓ · — |
| DropdownMenuSubMenu | 59.4 kB (0) · 9.2 kB CSS (0) | — | ✓ · ✓ · ✓ |
| NavHeadingMenu | 15.5 kB (0) · 3.5 kB CSS (0) | — | — · — · — |
| SegmentedControl | 83.8 kB (0) · 6.7 kB CSS (0) | — | — · — · — |
| SideNav | 75.7 kB (0) · 10.1 kB CSS (0) | — | — · — · — |
| SideNavHeading | 61.5 kB (0) · 10.0 kB CSS (0) | — | — · — · — |
| SideNavItem | 56.6 kB (0) · 9.8 kB CSS (0) | — | — · — · — |
| TableSelectionToolbar | 56.3 kB (0) · 11.8 kB CSS (0) | — | — · — · — |
| TabList | 35.8 kB (0) · 6.3 kB CSS (0) | — | — · — · — |
| TabMenu | 58.2 kB (0) · 9.8 kB CSS (0) | — | — · — · — |
| Toolbar | 35.2 kB (0) · 7.9 kB CSS (0) | — | — · — · — |
| TopNavHeading | 60.9 kB (0) · 9.8 kB CSS (0) | — | — · — · — |
| TopNavMegaMenu | 56.1 kB (0) · 10.6 kB CSS (0) | — | — · — · — |
| TreeList | 40.8 kB (0) · 5.3 kB CSS (0) | — | — · — · — |
| Typeahead | 65.0 kB (0) · 11.2 kB CSS (0) | — | — · — · — |
| lab/CommentPin | 48.4 kB (0) · 1.2 kB CSS (0) | — | — · — · — |
| LayerProvider | 64.4 kB (−1 B) · 9.4 kB CSS (0) | — | — · — · — |
Package size: @astryxdesign/core 6.48 MB packed (+380 B); no new dependencies.
API changes: none in this pull request
Committed API report behind this build: cli 9 rows, core 3 rows; run pnpm api:report.
Touched components checked; add ci:run-visual, ci:run-a11y or ci:run-rtl to run the full suites.
Generated by PR Enrichment workflow | View full report
There was a problem hiding this comment.
Changes requested. The fix itself works: in WebKit, with focus on the main region when the trigger is activated, the page stays at 129 px on this branch where main jumps to 192 px, and focus still returns to the opener. Three small corrections are needed before it lands.
- The new
BottomSheetCloseScrollandDialogCloseScrollspecs pass unchanged againstmainin Chromium and Playwright's Linux WebKit, because those engines focus the clicked button. After the scroll, focus the region withmain.focus({preventScroll: true}), and open withawait opener.evaluate(node => (node as HTMLElement).click())instead ofopener.click(); the button and backdrop cases then fail onmain(Expected 129, Received 192) and pass here. - The changeset lists DropdownMenu as fixed, but its close already passed
preventScroll: truebefore this change and its sheet returns focus to its own trigger, so the entry should name only BottomSheet and Dialog. - In
docs/families/overlay-dismissal.md, Open questions still says "FR9 fixes only the document focus returns in" and AV1 says the same, which now contradicts FR9's new no-scroll sentence, so both lines need the addition.
One non-blocking suggestion on the returnFocusForLastInput comment is inline.
[Automated review]
| } | ||
|
|
||
| async function openSheet(page: Page, opener: Locator): Promise<Locator> { | ||
| await opener.click(); |
There was a problem hiding this comment.
In Chromium and Playwright's Linux WebKit this click focuses the trigger itself, so the sheet records the trigger as its opener and nothing scrolls on main: unchanged, all three cases pass against a main Storybook. Put focus where Safari puts it, then activate the trigger without moving focus:
// in mountScrolled, after window.scrollTo(0, scrollOffset):
main.focus({preventScroll: true});
// here:
await opener.evaluate(node => (node as HTMLElement).click());With that, the Apply and scrim cases fail on main in WebKit (Expected: 129, Received: 192) and pass on this branch.
| } | ||
|
|
||
| async function openDialog(page: Page, opener: Locator): Promise<Locator> { | ||
| await opener.click(); |
There was a problem hiding this comment.
Same as the BottomSheet spec: this click focuses the trigger in Chromium and Linux WebKit, so the spec passes on main. Focus main with preventScroll: true after the scroll and open with await opener.evaluate(node => (node as HTMLElement).click());; the Cancel and backdrop cases then fail on main (Expected: 129, Received: 192) and pass here.
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [fix] BottomSheet, Dialog and DropdownMenu: the page no longer jumps after a sheet, a dialog or a menu closes in Safari and on iOS. Returning focus to the control that opened the overlay asks the browser not to scroll. WebKit focuses the nearest focusable ancestor of a tapped button, such as an app's `tabindex="-1"` main region, and records it as the opener; the focus return then scrolled the page to that region's top edge. The focus ring still follows the last input. |
There was a problem hiding this comment.
DropdownMenu's close already passed preventScroll: true before this change, and its sheet returns focus to its own trigger through finalFocusRef, so nothing changes for DropdownMenu users. Suggest starting the entry with: "[fix] BottomSheet and Dialog: the page no longer jumps after a sheet or a dialog closes in Safari and on iOS."
| target, in the opener's document, with the ring the last input in that | ||
| document calls for (`architecture:interaction-modality` INV1); a BottomSheet, | ||
| BottomSheetSwitcher, or Lightbox does the same in a Picture-in-Picture window. | ||
| The return does not scroll the page or any scroller to the return target, |
There was a problem hiding this comment.
With this sentence FR9 also owns scrolling during the return, but Open questions (line 344) still says "FR9 fixes only the document focus returns in" and AV1 (line 236) says the same. Please add "and that the return does not scroll" to both.
| /** | ||
| * Returns focus to `opener` after an overlay closes, with the ring the last | ||
| * input calls for. The opener was on screen when the overlay opened, and the | ||
| * page has not scrolled since, so the move reveals nothing. `preventScroll` |
There was a problem hiding this comment.
Non-blocking: "the page has not scrolled since" does not hold for a non-modal sheet, which has no scroll lock, so the page can scroll while it is open. Suggest keeping only the reason: "Return focus without a scroll. WebKit records the nearest focusable ancestor of a tapped button as the opener, such as a tabindex="-1" main region. A reveal of that region scrolls the page to its top edge."
…longer scrolls the page On Safari and iOS the page jumped after a sheet or dialog closed from a tap when its trigger sat inside a focusable region (a `tabindex="-1"` main landmark). WebKit focuses the nearest focusable ancestor of a tapped button, so the recorded opener was that region, and the pointer close's blur-and-refocus of the opener, with no `preventScroll`, made WebKit reveal the region: the page scrolled to its top edge. The scroll lock's old `window.scrollTo` on release cancelled that reveal for BottomSheet; Dialog returns focus after its lock releases, so it jumped before too. `returnFocusForLastInput(opener)` returns focus with `preventScroll: true` and the ring the last input calls for. BottomSheet's close, the stack's "Close all" return, Dialog's close, DropdownMenu's close and the return on removal use it. The opener was on screen when the overlay opened and the page has not moved since, so the return reveals nothing. Lightbox and MobileNav focus an opener the native close already focused, which moves nothing, and are unchanged. `family:overlay-dismissal` FR9 states that the return does not scroll the page or any scroller to the return target. Two browser specs, in Chromium and WebKit, close a BottomSheet and a Dialog whose trigger sits in a tall focusable region of a scrolled page by a control inside, the backdrop and Escape, and assert the page's offset and the trigger's place on screen; the unit tests pin the focus options of every return.
647f3c5 to
9e76574
Compare
|
/approve-spec 9e76574 |
There was a problem hiding this comment.
Approved; CI passed on this head.
In WebKit, with the trigger inside a focusable tabindex="-1" region of a scrolled page, closing a BottomSheet with Apply or the scrim, or a Dialog with Cancel or the backdrop, moved the page from 129 to 192 px on main and now leaves it at 129, with focus still returning to the opener. The new BottomSheetCloseScroll and DialogCloseScroll specs fail on main in WebKit and pass here, Chromium is unchanged, and the earlier comments on the specs, the changeset and the record are all addressed.
[Automated review]
User impact
On Safari and iOS, a page that holds a BottomSheet or Dialog trigger inside a focusable region (a
tabindex="-1"main landmark, as app routers and skip links set up) jumps when the sheet or dialog closes from a tap: Apply, Save, Done, the scrim or backdrop, or a swipe. The page scrolls so that the region's top edge meets the top of the viewport, 63 px on the docsite's component pages when the first example is open, 192 px when the page was not scrolled at all. Escape closes do not jump, and Chromium does not jump. The fix keeps the page where it was for every close path.Problem and solution fit
document.activeElementas the opener when the caller passes nofinalFocusRef, so the recorded opener is the tall region. On a pointer close,focusForLastInput(opener)blurs and refocuses the opener withfocusVisible: falseto drop the ring WebKit's own restore drew, and the refocus has nopreventScroll, so WebKit schedules a scroll-to-focused-element for the next rendering update. The region's top edge is below the viewport's top edge, so the reveal scrolls the page to it.<body>and scroll back to the saved offset on release. Thatwindow.scrollTocancelled WebKit's scheduled reveal. The lock now holds the page withoverflow: hiddenand restores nothing, so the reveal runs. Dialog's return runs after its lock releases, so Dialog had the same jump before that change.The fix is one rule at the one place that returns focus:
returnFocusForLastInput(opener)inutils/focusReturn.tsfocuses the opener withpreventScroll: trueand the ring the last input calls for. BottomSheet's close, the stack's "Close all" return, Dialog's close, DropdownMenu's close (which already passedpreventScroll) and the return on removal use it. The opener was on screen when the overlay opened and the page has not moved since, so the return has nothing to reveal.Expected behavior and authority
family:overlay-dismissalFR9 owns the focus return of every overlay member; this change adds to it that the return does not scroll the page or any scroller to the return target, and the reason WebKit needs the rule.component:DialogFR4 / AR2 andcomponent:BottomSheetFR9 / FR11 keep their return targets.Smallest restoration
One new internal helper, five call sites, two browser specs, the unit expectations that pin the focus options, one record sentence, one changeset. No public API, no visual change, no new default. Lightbox and MobileNav call
focus()once on an opener the native close already focused, which moves nothing, so they do not jump and are not changed.Evidence
Per-frame measurement (viewport 390×844, a
tabindex="-1"region whose top is at 192 px holds the trigger, page scrolled to 129; the value is the page's scroll offset after the close):overflow: hidden)Dialog (
core-dialog--default, same page): main WebKit Cancel 192, backdrop 192, Escape 129, before and after the scroll-lock change alike; this change 129 on every path. The docsite's BottomSheet page at phone width in WebKit: main 129 → 192 on Apply, scrim and swipe; with this change 129 on all four paths.BottomSheetCloseScroll.a11y.browser.spec.tsandDialogCloseScroll.a11y.browser.spec.tsfocus the region withpreventScrollafter the scroll and open with a programmatic click, so the region is the recorded opener in every engine, as a tap leaves it in Safari. Against a Storybook built from main, the four button and backdrop cases fail in WebKit ("Expected: 129, Received: 192") and the two Escape cases pass; all six pass in Chromium, whose reveal does not move the page in this geometry.finalFocusRef), and the focus ring policy: a pointer close still asks for no ring, a keyboard close leaves the ring to the browser.focusReturn.test.tspinsreturnFocusForLastInputtopreventScroll: truefor both modalities; the BottomSheet and Dialog unit tests pin the focus options of every return.Scope
Testing
pnpm vitest run --project=ui packages/core/src/BottomSheet packages/core/src/Dialog packages/core/src/DropdownMenu packages/core/src/utils/focusReturn.test.ts— 1008 passed.pnpm exec playwright test BottomSheetCloseScroll DialogCloseScrollagainst a built Storybook, Chromium and WebKit projects — 12 passed with the change; against a main build, the 4 WebKit button and backdrop cases fail with the 192 px offset and the 6 Chromium cases pass.pnpm -F @astryxdesign/core typecheck,pnpm check:knowledge,pnpm check:changesets,pnpm review:pre— clean.core-bottomsheet--showcaseandcore-dialog--defaultinside a talltabindex="-1"region on a scrolled page; the docsite's BottomSheet page at 390 px with touch emulation.Writing rubric results
R1 narration: the FR9 sentences state what the return does; no proposal or history.
R2 research: none in the record; the measurements live in this pull request.
R3 evidence: the new evidence row names the specs and the states, not a change.
R4 rejected alternatives: none added.
R5 change references: none.
R6 open questions: none.