edenspiekermann / a11y-toggle

A tiny script for accessible content toggles.
https://edenspiekermann.github.io/a11y-toggle/
MIT License
304 stars 21 forks source link

Doesn't work with element inside button #13

Closed derhedwig closed 8 years ago

derhedwig commented 8 years ago

Hi!

I noticed that, when you put an element inside of the toggle:

<button data-a11y-toggle="content-container" type="button">
  <span>test</span>
</button>

and click onto the element, i.e. span, instead of the button the event handler wouldn't find the target, because the span doesn't have a data-a11y-toggle attribute.

So, I suggest adding sth. like this:

// try the parent
if (!target) {
  var toggle = toggle.parentNode;
  var target = targetsMap[toggle.getAttribute(namespace)];
}
KittyGiraudel commented 8 years ago

Hey there. This issue has been reported as part of #7. Unfortunately, this toggle.parentNode solution would not work for deeply nested elements. I’ll issue a robust fix though. :)

KittyGiraudel commented 8 years ago

Fixed in https://github.com/edenspiekermann/a11y-toggle/releases/tag/1.0.2.