Skip to content

[popups] Fix programmatic focus return#4849

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

[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: 55a20ef

@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%) 🔺+7B(0.00%)

Details of bundle changes

Performance

Total duration: 1,420.31 ms +133.31 ms(+10.4%) | Renders: 50 (+0) | Paint: 2,157.81 ms +195.95 ms(+10.0%)

Test Duration Renders
Slider mount (300 instances) 195.00 ms 🔺+32.94 ms(+20.3%) 3 (+0)
Menu open (500 items) 95.72 ms 🔺+21.06 ms(+28.2%) 12 (+0)
Select open (500 options) 58.13 ms 🔺+13.14 ms(+29.2%) 14 (+0)
Tooltip mount (300 contained roots) 59.23 ms 🔺+10.47 ms(+21.5%) 1 (+0)

8 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 55a20ef
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a0bfa9489714c0008c12a57
😎 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.

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