Accordion icon indicating copy to clipboard operation
Accordion copied to clipboard

Incorrect animation height when using beforeOpen to lazyLoad Content

Open jonpfote opened this issue 3 years ago • 1 comments

I want to use beforeOpen to lazy load the content of my accordion. Lazy loading works, but the animation is wrong. Unfortunately, in your method showElement the height of the container (=how large it should be after onOpen) is calculated before the callback beforeOpen is run. (By lazy loading the content, the height changes.) That is why the accordion is not animating to the correct height. (In my example it is animating from hidden to 0px even though I add content in showElement.)

I think the cause of the bug is here: https://github.com/michu2k/Accordion/blob/de545323ec54e1379906756240552d7833fdc3f7/src/accordion.js#L249-L252

You can see the bug at: https://codepen.io/jonpfote/pen/WNzKoLm (I tested the bug with Chrome and Firefox)

I would like the order to be:

  1. call beforeOpen function (There I want to load and add the content to .ac-panel)
  2. calculate 'height' of content (for animation)
  3. start animation

Currently, the order is 2 -> 1 -> 3. That means beforeOpen can't be used to lazy load the content. (if the height of the container changes)

I tried to call accordion.update() in my beforeOpen function, but this does not solve the issue

Please tell me if I missed something. (For example, if there is another way to lazy load content)

jonpfote avatar Aug 09 '22 20:08 jonpfote

Hi @jonpfote Thanks for reporting the bug. I will look into this issue.

michu2k avatar Aug 12 '22 07:08 michu2k

Fixed in v3.3.2

michu2k avatar Aug 15 '22 09:08 michu2k

Thank you 👍

jonpfote avatar Aug 15 '22 16:08 jonpfote