Skip to content

[popups] Fix non-modal focus-out close and tabindex management - #5030

Merged
atomiks merged 5 commits into
mui:masterfrom
atomiks:popups/focus-out-tabindex-fixes
Jun 12, 2026
Merged

atomiks merged 5 commits into
mui:masterfrom
atomiks:popups/focus-out-tabindex-fixes

Conversation

@atomiks

@atomiks atomiks commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Three focus-management fixes in FloatingFocusManager (the shared focus manager used by Dialog, Popover, Menu, etc.):

  • Reset isPointerDownRef after a click-trigger pointerdown. It was set when pointerdown landed on a [data-base-ui-click-trigger] element but only ever reset by the Safari workaround on the reference, so clicking a nested click-trigger inside a non-modal popup permanently suppressed every later focus-out close for the lifetime of the instance (and across sessions for keep-mounted popups).
  • Mark data-tabindex when writing tabindex="0". The empty-content branch of handleTabIndex wrote tabindex="0" without the marker, so the externally-managed early-return then treated our own write as user-authored and could never downgrade the container back to -1 once content became tabbable.
  • Reset pointerDownOutsideRef on effect teardown so a stale true doesn't leak into a keep-mounted popup's next open.

Adds a closeOnFocusOut={false} regression test.

- Reset isPointerDownRef after a click-trigger pointerdown so focus-out
  closing isn't permanently suppressed (B1).
- Mark data-tabindex when writing tabindex=0 so the popup can be downgraded
  back to -1 once content becomes tabbable (B2).
- Reset pointerDownOutsideRef on effect teardown so a stale value doesn't
  leak into a keep-mounted popup's next open (B3).
- Add a closeOnFocusOut={false} regression test.
@atomiks atomiks added type: bug It doesn't behave as expected. component: dialog Changes related to the dialog component. component: popover Changes related to the popover component. labels Jun 12, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@5030
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@5030
    

commit: e7ca20d

@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 🔺+72B(+0.02%) 🔺+11B(+0.01%)

Details of bundle changes

Performance

Total duration: 1,214.45 ms +63.66 ms(+5.5%) | Renders: 50 (+0) | Paint: 1,851.29 ms +99.18 ms(+5.7%)

Test Duration Renders
Mixed surface mount (app-like density) 88.36 ms 🔺+20.05 ms(+29.3%) 5 (+0)
Popover mount (300 instances) 72.52 ms 🔺+12.99 ms(+21.8%) 1 (+0)

10 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 e7ca20d
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a2c0b6a7182720007376c39
😎 Deploy Preview https://deploy-preview-5030--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 08:12
@atomiks
atomiks marked this pull request as ready for review June 12, 2026 08:12

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 several focus-management edge cases in FloatingFocusManager (shared by popups like Dialog/Popover/Menu) that could incorrectly suppress focus-out closing or leave tabindex management in a stuck state, especially for non-modal and keep-mounted popups.

Changes:

  • Ensure isPointerDownRef is reset after clicking a nested [data-base-ui-click-trigger] element so future focus-out closes aren’t suppressed.
  • Mark data-tabindex when the manager sets tabindex="0" to avoid misclassifying the value as user-authored and freezing later tabIndex updates.
  • Reset pointerDownOutsideRef on interaction-tracking effect teardown to prevent stale state across keep-mounted reopen cycles.
  • Add regression tests covering closeOnFocusOut={false}, nested click-trigger interactions, and managed tabIndex downgrading when tabbable content appears.

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 Fixes pointer/focus state reset and ensures internal tabindex writes are properly marked for continued management.
packages/react/src/floating-ui-react/components/FloatingFocusManager.test.tsx Adds regression tests for non-modal focus-out behavior, nested click-trigger behavior, and tabindex management transitions.

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

@atomiks
atomiks merged commit 4292cfa into mui:master Jun 12, 2026
6 checks passed
@atomiks
atomiks deleted the popups/focus-out-tabindex-fixes branch June 12, 2026 13:45
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: 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.

3 participants