Skip to content

[popups] Fix programmatic focus return#4849

Open
atomiks wants to merge 1 commit into
mui:masterfrom
atomiks:codex/fix-programmatic-focus-return
Open

[popups] Fix programmatic focus return#4849
atomiks wants to merge 1 commit into
mui:masterfrom
atomiks:codex/fix-programmatic-focus-return

Conversation

@atomiks
Copy link
Copy Markdown
Contributor

@atomiks atomiks commented May 19, 2026

Fixes #4169

Controlled dialogs and popovers can be associated with a triggerId even when a separate control opened them programmatically. This returns focus to that originating control on close instead of always preferring the associated trigger.

Root cause

The default return-focus path preferred the associated reference trigger, even for programmatic opens where the focused opener was a different control.

Changes

  • Prefer the previously focused opener for programmatic popup opens.
  • Keep reference-first focus restoration for trigger-opened popups and disconnected-reference fallback behavior.
  • Add coverage for a controlled Dialog triggerId opened from a separate control.

@atomiks atomiks added component: alert dialog Changes related to the alert dialog component. type: bug It doesn't behave as expected. component: dialog Changes related to the dialog component. accessibility a11y component: popover Changes related to the popover component. labels May 19, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 19, 2026

commit: f6a8e63

@code-infra-dashboard
Copy link
Copy Markdown

code-infra-dashboard Bot commented May 19, 2026

Bundle size

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

Details of bundle changes

Performance

Total duration: 1,203.16 ms -120.51 ms(-9.1%) | Renders: 50 (+0) | Paint: 1,842.00 ms -170.38 ms(-8.5%)

Test Duration Renders
Scroll Area mount (300 instances) 83.79 ms ▼-23.89 ms(-22.2%) 3 (+0)
Mixed surface mount (app-like density) 71.65 ms ▼-20.39 ms(-22.1%) 5 (+0)
Select open (500 options) 44.28 ms ▼-13.27 ms(-23.1%) 14 (+0)

9 tests within noise — details


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

@atomiks atomiks force-pushed the codex/fix-programmatic-focus-return branch from 3e76c18 to 47f079d Compare May 19, 2026 05:50
@netlify
Copy link
Copy Markdown

netlify Bot commented May 19, 2026

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 3e76c18
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a0bf967f9cef500082be585
😎 Deploy Preview https://deploy-preview-4849--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 force-pushed the codex/fix-programmatic-focus-return branch from 47f079d to 55a20ef Compare May 19, 2026 05:52
@netlify
Copy link
Copy Markdown

netlify Bot commented May 19, 2026

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 47f079d
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a0bfa1d31110200087cc64d
😎 Deploy Preview https://deploy-preview-4849--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.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 19, 2026

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit f6a8e63
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a0eca053c16ce00083f9fdd
😎 Deploy Preview https://deploy-preview-4849--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 force-pushed the codex/fix-programmatic-focus-return branch from 55a20ef to 9c7e953 Compare May 21, 2026 08:58
@atomiks atomiks force-pushed the codex/fix-programmatic-focus-return branch from 9c7e953 to f6a8e63 Compare May 21, 2026 09:01
@atomiks atomiks marked this pull request as ready for review May 21, 2026 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accessibility a11y component: alert dialog Changes related to the alert dialog component. component: dialog Changes related to the dialog component. component: popover Changes related to the popover component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Accessibility: Focus moves to the wrong trigger when using "Open programmatically" buttons

1 participant