Accordion
Accordion copied to clipboard
Incorrect animation height when using beforeOpen to lazyLoad Content
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:
- call
beforeOpenfunction (There I want to load and add the content to.ac-panel) - calculate 'height' of content (for animation)
- 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)
Hi @jonpfote Thanks for reporting the bug. I will look into this issue.
Fixed in v3.3.2
Thank you 👍