Skip to content

Dialog/Drawer: fix focus-restore scroll and dispose-while-open cleanup#42544

Merged
mdo merged 3 commits into
v6-devfrom
mdo/audit-dialog-drawer-issues
Jun 27, 2026
Merged

Dialog/Drawer: fix focus-restore scroll and dispose-while-open cleanup#42544
mdo merged 3 commits into
v6-devfrom
mdo/audit-dialog-drawer-issues

Conversation

@mdo

@mdo mdo commented Jun 23, 2026

Copy link
Copy Markdown
Member

Two small dialog/drawer fixes, one per commit:

mdo added 2 commits June 23, 2026 15:32
Pass { preventScroll: true } when returning focus to the trigger after
close, so the page no longer jumps to the trigger (or to the top when
scroll-padding-top is set). Fixes #38070, #41615, #35391.
dispose() now closes the native <dialog> and removes the dialog-open
body class if the instance is torn down while still open (e.g. an SPA
route change), instead of leaving overflow: hidden stuck on the body.
Fixes #35934, #39910.
@mdo mdo requested a review from a team as a code owner June 23, 2026 22:33
@mdo mdo mentioned this pull request Jun 26, 2026
8 tasks
@mdo mdo added this to v6.0.0 Jun 27, 2026
@github-project-automation github-project-automation Bot moved this to Inbox in v6.0.0 Jun 27, 2026
@mdo mdo requested a review from Copilot June 27, 2026 02:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses two usability/cleanup issues in the new native-<dialog>-based Dialog/Drawer components: preventing scroll jumps when restoring focus to the trigger, and ensuring body scroll is restored if a component is disposed while still open.

Changes:

  • Restore focus to the trigger with focus({ preventScroll: true }) after Drawer/Dialog close via the data API, avoiding page scroll jumps.
  • Add DialogBase.dispose() behavior to close an open native <dialog> and remove dialog-open from <body> when disposing mid-open.
  • Extend unit tests to cover dispose-while-open cleanup and the new preventScroll focus behavior; adjust bundle size thresholds.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
js/src/drawer.js Updates data-API focus restoration to use { preventScroll: true }.
js/src/dialog.js Updates data-API focus restoration to use { preventScroll: true }.
js/src/dialog-base.js Adds dispose() cleanup to close an open dialog and restore body scroll.
js/tests/unit/drawer.spec.js Adds dispose-while-open test; updates focus expectation to include preventScroll.
js/tests/unit/dialog.spec.js Adds dispose-while-open test; updates focus expectation to include preventScroll.
.bundlewatch.config.json Updates max bundle size thresholds for generated JS artifacts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread js/src/dialog-base.js
Comment on lines +120 to +129
dispose() {
// If disposed while still open, close the native <dialog> and restore body
// scroll. Otherwise `dialog-open` (overflow: hidden) would stay stuck on the
// body — e.g. when an SPA tears the component down mid-navigation.
if (this._element.open) {
this._closeAndCleanup()
}

super.dispose()
}
@mdo mdo merged commit aa27369 into v6-dev Jun 27, 2026
13 checks passed
@mdo mdo deleted the mdo/audit-dialog-drawer-issues branch June 27, 2026 03:14
mdo added a commit that referenced this pull request Jun 27, 2026
…42575)

* Tests: assert dialog-open on documentElement in dispose-while-open specs

The dispose-while-open specs added in #42544 asserted the scroll-lock
class on document.body, but #42545 moved the lock to the root element
(documentElement). The two changes were each green in isolation but
broke once both landed on v6-dev. Align these specs with the rest of
the suite, which already asserts on documentElement.

* Build: bump bundlewatch thresholds for cumulative JS growth on v6-dev

bootstrap.bundle.js (83.15KB) and bootstrap.js (54.39KB) now exceed the
prior thresholds after the dialog/drawer/tooltip/popover/menu fixes
landed; each PR bumped only relative to its own base.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Inbox

Development

Successfully merging this pull request may close these issues.

2 participants