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

Prevent bubbling for tooltips of nested elements #259

Closed
tilonorrinco opened this issue Jul 8, 2018 · 4 comments
Closed

Prevent bubbling for tooltips of nested elements #259

tilonorrinco opened this issue Jul 8, 2018 · 4 comments

Comments

@tilonorrinco
Copy link

Hello!
In my project there are two nested divs: one inside another. Each div has its own tooltip.
The problem is: when I hover nested div, there are two tooltips: one of hovered div and other -- of its parent due to event bubbling. How can I prevent such behavior? The result I try to get: hovering nested div there should be only one tooltip: the tooltip of this div. Here you can see the example of problem:
https://codesandbox.io/s/6y6k0kl1lw
Thank you!

@atomiks
Copy link
Owner

atomiks commented Jul 8, 2018

You can control the functionality of tooltips with custom logic. So while there's not (that I can think of) a declarative/automatic solution that the library does, you can always do it yourself.

In particular, you can make the parent listen for mouseoff and hide the tooltip. However, you'll might need to account for legitimate children of the parent who don't have a tooltip.

Let me know if this works.

parent.addEventListener('mouseout', e => {
  if (e.target._tippy) {
    parent._tippy.hide()
  }
})

@KABBOUCHI
Copy link
Contributor

KABBOUCHI commented Jul 9, 2018

https://codesandbox.io/s/74x60rz3wq

@tilonorrinco
Copy link
Author

Thanks a lot, it works!

@atomiks
Copy link
Owner

atomiks commented Jul 9, 2018

Ha yeah, mouseout not mouseoff 🤣

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants