Skip to content

[dialog] Fix confirmation return focus#5024

Open
atomiks wants to merge 1 commit into
mui:masterfrom
atomiks:codex/drawer-close-confirmation-focus
Open

[dialog] Fix confirmation return focus#5024
atomiks wants to merge 1 commit into
mui:masterfrom
atomiks:codex/drawer-close-confirmation-focus

Conversation

@atomiks

@atomiks atomiks commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

The new Drawer close confirmation demo exposed a focus restore bug: after canceling an outside-press close and opening a confirmation dialog, choosing “Go back” could send focus back to the original trigger instead of the field inside the still-open dialog/drawer.

Steps

https://deploy-preview-5024--base-ui.netlify.app/react/components/drawer#close-confirmation

  1. Click 'Tweet' trigger.
  2. Click textarea and type 'x'.
  3. Click outside the Drawer (on its backdrop) with a pointer.
  4. Press 'Go Back' using keyboard Enter.
  5. Focus returns to 'Tweet' despite drawer being open and modal. Focus is lost.

Root cause

When the outside press blurred the focused field to the document body, the detached confirmation dialog had no useful pre-open focus target to restore.

Changes

  • Records the focused element when focus is lost from inside a floating element to no concrete destination.
  • Adds a Chromium regression test for the canceled-close confirmation flow.

@atomiks atomiks added component: dialog Changes related to the dialog component. component: drawer Changes related to the drawer component. type: bug It doesn't behave as expected. labels Jun 12, 2026 — with ChatGPT Codex Connector
@pkg-pr-new

pkg-pr-new Bot commented Jun 12, 2026

Copy link
Copy Markdown

commit: e2d2ffe

@code-infra-dashboard

code-infra-dashboard Bot commented Jun 12, 2026

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+33B(+0.01%) 🔺+18B(+0.01%)

Details of bundle changes

Performance

Total duration: 1,217.74 ms -26.36 ms(-2.1%) | Renders: 50 (+0) | Paint: 1,824.89 ms -53.62 ms(-2.9%)

Test Duration Renders
Checkbox mount (500 instances) 70.19 ms ▼-29.64 ms(-29.7%) 1 (+0)

11 tests within noise — details


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Jun 12, 2026

Copy link
Copy Markdown

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit e2d2ffe
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a2b7a55415c320008df10f7
😎 Deploy Preview https://deploy-preview-5024--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@atomiks atomiks requested a review from Copilot June 12, 2026 03:22
@atomiks atomiks marked this pull request as ready for review June 12, 2026 03:22

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

Fixes a focus restoration edge case in Base UI’s floating focus management where an outside-press (backdrop) can temporarily blur focus to document.body, causing a subsequently opened “close confirmation” dialog to restore focus to the original trigger instead of back into the still-open modal.

Changes:

  • Record the last focused element inside the floating element when focus is lost with no concrete relatedTarget (e.g. blur-to-body on backdrop press).
  • Add a browser-only regression test covering the “outside press → canceled close → confirmation dialog → Go back → focus returns into dialog” flow.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/react/src/floating-ui-react/components/FloatingFocusManager.tsx Records the focused element when focus is lost to no relatedTarget, enabling correct focus restoration after a transient blur-to-body.
packages/react/src/dialog/root/DialogRoot.test.tsx Adds a non-JSDOM regression test validating focus returns into the dialog after closing an outside-press confirmation.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: dialog Changes related to the dialog component. component: drawer Changes related to the drawer component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants