Tooltip stays open when you switch tabs
See original GitHub issue🐛 Bug report
The tooltip does not hide when the tab moves out of focus.
💥 Steps to reproduce
- Go to https://codesandbox.io/s/vibrant-fermat-1mxhc?file=/src/index.js or https://chakra-ui.com/docs/overlay/tooltip#tooltip-with-focusable-content
- Click on the “Button” which is wrapped in
<Tooltip />
- Switch the tab and move your cursor
- Revisit the original page (with the Button), the tooltip will not be hidden.
💻 Link to reproduction
Click the button here: https://chakra-ui.com/docs/overlay/tooltip#tooltip-with-focusable-content
CodeSandbox reproduction: https://codesandbox.io/s/vibrant-fermat-1mxhc?file=/src/index.js Steps:
- Click on the button.
- Switch to a different tab.
- Return to the codesandbox.
🧐 Expected behavior
The tooltip should not be visible when you return to the tab after switching to a different tab.
🧭 Possible Solution
Remove “focus” on the element when the user moves out of the site.
🌍 System information
Software | Version(s) |
---|---|
Chakra UI | 1.6.3 |
Browser | Chrome |
Operating System | Arch Linux |
📝 Additional information
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
Tooltip Re-opens upon return to tab/window after clicking ...
The Tooltip of the IconButton is not properly closing when navigating away from the tab/window it is being used on.
Read more >Bootstrap Tooltip attached to Anchor keeps opened once new ...
I noticed that the bootstrap tooltip keeps opened when clicking on Anchor and the new tab is opened. Once you go back to...
Read more >Tooltip stays on screen forever until you return to the tab that ...
Alt-tabbing to a different application won't make it disappear. The only thing that will make it disappear is switching back to the tab...
Read more >How to identify which program has left a portion of its UI ...
Find the tab it came from and just move your mouse around. The tooltip should disappear. (Unfortuantely, there's no easy way to determine...
Read more >89759 - Blacked-out tooltip appears on tab mouseover
3. Move the mouse away from the tab. What is the expected result? A tool tip should display showing the full title of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
To solve this problem without change the current api behavior is to use
useRef()
. This code should be typescript compitatble.@roerohan Your solution indeed better than mine since mine can cause some accessibility issue.
blur
should be used carefully. And based on the issue #500 you refer, there are some questions we must ask ourselves as Devs. I wonder what kinds of user cases we are trying to propose.Button is "disabled”, Tooltip is not. Then there is not accessibility for disabled button since the disabled button cannot be focused. So Tooltip will be only beneficial for regular user.
So my own solution based on yours and the issue, might be that we will never “disable” the button by using
disabled
, using CSS instead, to fully cover all cases I can imagine so far. Notice that even when button is disabled. We can still use “Tab” key to get the button and read the disabled Tooltip hint. It’s quite lengthy but it should cover all your needs along with the issue #500.You can play around the code here. https://codesandbox.io/s/ancient-pond-yl20h?file=/src/index.tsx