michu2k / Accordion

Accordion module created in pure javascript & CSS. Very useful to create FAQ lists on your website.
https://michu2k.github.io/Accordion/
MIT License
357 stars 77 forks source link

onClose is triggered on all ancestors of a closed panel #66

Closed xemlock closed 1 year ago

xemlock commented 1 year ago

onClose is triggered on all ancestors of a closed panel, but should only be triggered on the closed panel itself.

Using nested example from https://michu2k.github.io/Accordion/:

new Accordion(['.nested-accordion-parent', '.nested-accordion-child'], {
  onClose: (el) => console.log('onClose',el)
}

after closing "Nested 1" accordion we get the following in the browser console:

onClose <div class=​"ac js-enabled" id=​"ac-5">​…​</div>​
onClose <div class=​"ac js-enabled is-active" id=​"ac-4">​…​</div>

The second onClose shouln't be executed, because the parent panel is still open.

michu2k commented 1 year ago

Hi @xemlock Thanks for letting me know that onClose() is not working as expected. The fix is already on the prerelease branch and will appear in the next update.