question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

  1. 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
  2. Click on the “Button” which is wrapped in <Tooltip />
  3. Switch the tab and move your cursor
  4. 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:

  1. Click on the button.
  2. Switch to a different tab.
  3. 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

https://user-images.githubusercontent.com/42958812/119809624-f10e0600-bf02-11eb-8368-6b44fd1ac693.mp4

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
aboveyunhaicommented, May 27, 2021

To solve this problem without change the current api behavior is to use useRef(). This code should be typescript compitatble.

const btnRef = useRef<HTMLButtonElement>(null);

<Tooltip hasArrow label="Search places">
  <Button
     ref={btnRef}
     onClick= {
     // whatever your functions here
     // blur at the end of the click to remove the button focus 
     
     if (btnRef.current) btnRef.current.blur()
     }
   >
     Button
   </Button>
</Tooltip>
1reaction
aboveyunhaicommented, May 28, 2021

@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.

  const btnRef = useRef<HTMLButtonElement>(null);
  const [isDisable, setDis] = useState(false);
  const [isTooltipDis, setTooltipDis] = useState(false);

  <Tooltip hasArrow
    label={isDisable ? "button is disabled" : "I'm a tooltip"}
    isDisabled={isTooltipDis}
  >
    <Box  display={"inline-block"}  cursor={isDisable ? "not-allowed" : "pointer"}>
      <Button ref={btnRef} pointerEvents={isDisable ? 'none' : 'auto'} opacity={isDisable ? 0.65 : 1}
        onClick={() => {
          if (isDisable) return;
          console.log('running ')
        }}
        onMouseOut={() => { if (btnRef.current) btnRef.current.blur(); }}
      >
        Button
      </Button>
    </Box>
  </Tooltip>

You can play around the code here. https://codesandbox.io/s/ancient-pond-yl20h?file=/src/index.tsx

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found