Skip to content

[focus] Don't steal initial focus if focus already moved inside the floating element#4775

Merged
atomiks merged 10 commits into
mui:masterfrom
stefee:stefee-patch-1
May 14, 2026
Merged

[focus] Don't steal initial focus if focus already moved inside the floating element#4775
atomiks merged 10 commits into
mui:masterfrom
stefee:stefee-patch-1

Conversation

@stefee
Copy link
Copy Markdown
Contributor

@stefee stefee commented May 8, 2026

Alternative solution to #4721 (also includes the fix from that PR although it wasn't directly related).

FloatingFocusManager schedules initial focus via queueMicrotask + RAF. Between when the microtask runs and when the RAF fires, something can legitimately move focus inside the floating element (e.g. a child popup opening in response to a click). The pending RAF would then override that focus, closing the child popup.

Add a guard option to enqueueFocus that is evaluated inside the RAF callback before calling .focus(). Pass a guard in FloatingFocusManager that skips the initial focus if the active element is already inside the floating element.

stefee added 2 commits May 1, 2026 17:50
…loating element

`FloatingFocusManager` schedules initial focus via `queueMicrotask` + RAF.
Between when the microtask runs and when the RAF fires, something can
legitimately move focus inside the floating element (e.g. a child popup
opening in response to a click). The pending RAF would then override that
focus, closing the child popup.

Add a `guard` option to `enqueueFocus` that is evaluated inside the RAF
callback before calling `.focus()`. Pass a guard in `FloatingFocusManager`
that skips the initial focus if the active element is already inside the
floating element.
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 8, 2026

commit: e059d1c

@code-infra-dashboard
Copy link
Copy Markdown

code-infra-dashboard Bot commented May 8, 2026

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+90B(+0.02%) 🔺+14B(+0.01%)

Details of bundle changes

Performance

Total duration: 1,130.80 ms -75.33 ms(-6.2%) | Renders: 50 (+0) | Paint: 1,726.52 ms -115.54 ms(-6.3%)

Test Duration Renders
Checkbox mount (500 instances) 64.59 ms ▼-16.31 ms(-20.2%) 1 (+0)

11 tests within noise — details


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

@netlify
Copy link
Copy Markdown

netlify Bot commented May 8, 2026

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit e059d1c
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a059fbea705f0000891a038
😎 Deploy Preview https://deploy-preview-4775--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 added type: bug It doesn't behave as expected. scope: all components Widespread work has an impact on almost all components. labels May 11, 2026
@atomiks atomiks merged commit 930bdd5 into mui:master May 14, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: all components Widespread work has an impact on almost all components. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants