Skip to content

[tooltip] Preserve focus-opened tooltip on hover leave#4884

Open
michaldudak wants to merge 2 commits into
mui:masterfrom
michaldudak:codex/tooltip-focus-hover-leave
Open

[tooltip] Preserve focus-opened tooltip on hover leave#4884
michaldudak wants to merge 2 commits into
mui:masterfrom
michaldudak:codex/tooltip-focus-hover-leave

Conversation

@michaldudak
Copy link
Copy Markdown
Member

@michaldudak michaldudak commented May 22, 2026

Summary

  • Keep a tooltip opened by focus open when the pointer leaves the focused trigger.
  • Continue closing it on blur or Escape.
  • Add regression coverage for focus -> mouseLeave -> blur/Escape.

Bug

A tooltip can be opened by focus and then closed by hover leave while the trigger still has focus. That leaves keyboard users with a tooltip that disappears even though the focus-open condition is still true.

Reproduction

Test plan

  • pnpm test:jsdom TooltipRoot --no-watch
  • pnpm test:chromium TooltipRoot --no-watch

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 22, 2026

commit: 53583d5

@code-infra-dashboard
Copy link
Copy Markdown

code-infra-dashboard Bot commented May 22, 2026

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+347B(+0.07%) 🔺+116B(+0.08%)

Details of bundle changes

Performance

Total duration: 1,235.40 ms -156.25 ms(-11.2%) | Renders: 50 (+0) | Paint: 1,885.71 ms -243.36 ms(-11.4%)

Test Duration Renders
Tabs mount (200 instances) 233.51 ms ▼-59.82 ms(-20.4%) 4 (+0)
Tooltip mount (300 contained roots) 49.07 ms ▼-13.12 ms(-21.1%) 1 (+0)

10 tests within noise — details


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

@michaldudak michaldudak added type: bug It doesn't behave as expected. component: tooltip Changes related to the tooltip component. labels May 22, 2026
@netlify
Copy link
Copy Markdown

netlify Bot commented May 22, 2026

Deploy Preview for base-ui ready!

Built without sensitive environment variables

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

Copy link
Copy Markdown
Member Author

michaldudak commented May 22, 2026

Codex Review (GPT-5.5)

Reviewed the full PR diff against freshly fetched upstream/master. Dominant type: bug-fix, with regression-test coverage for Tooltip focus/hover ownership.

1. Bugs / Issues (None)

I did not find any branch-relevant correctness issues in the changed hover ownership path.

Root Cause & Patch Assessment

The patch addresses the actual ownership problem: a focus-opened tooltip should not be treated as hover-owned while focus remains on the trigger or popup. Updating syncOpenEvent to let focus upgrade a hover-open event, then gating hover-close through isNonHoverOpenEvent(..., focusOwned), keeps the tooltip open for focus ownership without making stale focus events permanently sticky after blur.

Test Coverage Assessment

The new Tooltip tests cover the important regressions: focus-open -> mouse leave -> blur/Escape, hover-open -> focus -> mouse leave, and pending hover-open not overwriting focus ownership. These run through the existing contained/detached/multiple-detached trigger matrix.

Validated:
pnpm test:jsdom TooltipRoot --no-watch
pnpm test:chromium TooltipRoot --no-watch
pnpm test:jsdom useHoverReferenceInteraction --no-watch
pnpm test:chromium useHoverReferenceInteraction --no-watch
pnpm prettier --check ...
pnpm eslint ...
pnpm typescript

I did not separately replay the new regression tests on upstream/master.

Recommendation

Approve ✅

The implementation is narrowly scoped, matches the shared hover-interaction architecture, follows the repo’s DOM utility conventions, and the relevant Tooltip/hook/type/lint validation passes.

@michaldudak michaldudak marked this pull request as ready for review May 22, 2026 11:29
@atomiks
Copy link
Copy Markdown
Contributor

atomiks commented May 22, 2026

I've noticed this in the past, but didn't consider it to be important to fix or possibly even desirable, especially without :focus-visible checks. I think we can leave this off?

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants