Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tooltip] Hide Tooltip when its child gets disabled #891

Open
chudesno opened this issue Nov 28, 2024 · 10 comments
Open

[Tooltip] Hide Tooltip when its child gets disabled #891

chudesno opened this issue Nov 28, 2024 · 10 comments
Assignees
Labels
component: tooltip This is the name of the generic UI component, not the React module!

Comments

@chudesno
Copy link

chudesno commented Nov 28, 2024

Steps to reproduce

Steps:

  1. Open this link to live example: https://codesandbox.io/p/sandbox/long-http-sjxfvz?workspaceId=93f2e57a-b3c6-40d3-8a9d-fec380821dae
  2. Click anywhere on the page and press tab to give focus to one of the buttons. Tooltip appears.
  3. Press Enter on the keyboard. This disables the focused button.

Current behavior

Tooltip remains visible until another button within the same Provider gets focused.

Expected behavior

Tooltip should get closed as soon as it becomes disabled.

Context

The original issue was spotted on Material UI and reported here mui/material-ui#44280
The root cause seems to be the React itself missing blur event as disable flag gets set by React itself. See: facebook/react#9142

Your environment

npx @mui/envinfo

System:
OS: macOS 12.6.1
Binaries:
Node: 20.16.0 - ~/.nvm/versions/node/v20.16.0/bin/node
npm: 10.8.1 - ~/.nvm/versions/node/v20.16.0/bin/npm
pnpm: 9.13.2 - ~/.nvm/versions/node/v20.16.0/bin/pnpm
Browsers:
Chrome: 131.0.6778.86
Edge: 131.0.2903.70
Safari: 15.6.1

The issue is reproducible in Chrome and Safari, but not in Firefox.

Search keywords: Tooltip blur onBlur disabled

@chudesno chudesno added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Nov 28, 2024
@chudesno
Copy link
Author

The pull request for Material UI has been put on hold in favor of Base UI: mui/material-ui#44507
Attempted solution is to listen to native blur additionally, which appears to be fired reliably.
Would love to create a pull request here, if issue is acknowledged by maintainer.

@mj12albert mj12albert added status: waiting for author Issue with insufficient information component: tooltip This is the name of the generic UI component, not the React module! labels Nov 28, 2024
@mj12albert mj12albert changed the title Hide Tooltip when its child gets disabled [Tooltip] Hide Tooltip when its child gets disabled Nov 28, 2024
@mj12albert
Copy link
Member

@chudesno I'm afraid your sandbox is crashing 😐
The AnchorButton must be placed within Tooltip.Root:

<React.StrictMode>
    <Demo />
    <Demo />
    <AnchorButton>FFF</AnchorButton>
</React.StrictMode>

@mj12albert mj12albert removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Nov 28, 2024
@chudesno
Copy link
Author

My bad! Sandbox is fixed now. @mj12albert please, take another look

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Nov 28, 2024
@mj12albert
Copy link
Member

Expected behavior
Tooltip gets hidden as the disabled button looses focus automatically.

Maybe it should close as soon it becomes disabled? 🤔

@chudesno
Copy link
Author

Yes, absolutely. What I meant here is that blur gets fired by browser when button gets disabled and the focus moves to body. onBlur does not fire though, so it remains open.

@colmtuite
Copy link
Contributor

colmtuite commented Nov 28, 2024

The focus on becoming disabled seems odd/unnecessary here? Tooltip should close when the button is activated by any means, right @atomiks? Currently, it closes when you click or press ESC, but not when you activate the button via Space or Enter.

@atomiks
Copy link
Contributor

atomiks commented Dec 4, 2024

The focus on becoming disabled seems odd/unnecessary here?

If disabled was changed from an external action, then dismissing the tooltip upon trigger click/press is still not enough (though it would likely solve most cases)

@TheOneTheOnlyJJ
Copy link

Is there any update on this?

@atomiks
Copy link
Contributor

atomiks commented Feb 18, 2025

@TheOneTheOnlyJJ the issue is largely resolved in the latest versions of Base UI for button triggers as a result of the linked PR above (floating-ui/floating-ui#3145)

https://codesandbox.io/p/sandbox/priceless-resonance-6xmhjr

When pressing Enter/Space the tooltip disappears. It doesn't address the edge case above (#891 (comment)) but I figure that's quite a bit rarer.

@atomiks atomiks removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Feb 18, 2025
@TheOneTheOnlyJJ
Copy link

Would you happen to have a rough idea of when it will land in Material UI?

I opened mui/material-ui#44280 some 4 months ago, and it seems like it was fixed given what I'm reading here, but I still have the same issue.
The problem, as seen in the code sandbox from there, is still present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: tooltip This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

5 participants