Twikito / easy-toggle-state

A tiny JavaScript library to easily toggle the state of any HTML element in any contexts, and create UI components in no time.
https://twikito.github.io/easy-toggle-state/
MIT License
281 stars 35 forks source link

Using data-toggle-outside with a trigger containing another tag #92

Closed lukaszwnek closed 4 years ago

lukaszwnek commented 4 years ago

Hello! First of all, thank you for this amazing library, great job!

I'm trying to implement a tooltip that would open after clicking a button with an img tag inside of it:

HTML

<button data-toggle-class-on-target="hidden" data-toggle-target=".tooltip" data-toggle-event="click" data-toggle-outside>
  <img src="https://secure.gravatar.com/avatar/37640f3902ef08c7fad7d306c912ebf0?d=identicon&s=200">
</button>
<span class="tooltip hidden">Awesome tooltip</span>

CSS

.hidden {
  display: none !important;
}

.tooltip {
  background-color: #00b074;
  color: white;
}

button {
  cursor: pointer;
  border: none;
  margin: 0;
  padding: 0;
  width: auto;
  overflow: visible;
  background: transparent;
  color: inherit;
  font: inherit;
  line-height: normal;
  outline: none;
}

img {
  border-radius: 50%;
  width: 100px;
  height: 100px;
}

https://codepen.io/lukaszwnek/pen/pobVZQo

However, clicking the button doesn't seem to show the tooltip. It starts working when I either:

  1. remove the data-toggle-outside attribute from the button (which I don't want to do since I need that to close it).
  2. moving all the data-toggle attributes to the img (but this goes against your own recommendation to use buttons as triggers).

The issue isn't limited to the img tag, from what I've seen it persists with any tag inside of the button (only plain text works).

It feels like a bug, but maybe there's something wrong with my setup? I'd really appreciate your opinion @Twikito.

Thanks!

Twikito commented 4 years ago

Hi @lukaszwnek πŸ‘‹

Ok, let me investigate.

Edit: Ok, I got it.

Twikito commented 4 years ago

Hey @lukaszwnek πŸ‘‹

It should now be fixed. Can you confirm, please?

lukaszwnek commented 4 years ago

@Twikito Yes, the new version fixed the issue! Thank you so much for such a quick response and for implementing the fix in no time! Really impressive stuff, keep up the good work!

Cheers! 🍻