fancyapps / ui

A library of JavaScript UI components, includes the best lightbox - Fancybox5
https://fancyapps.com/
Other
721 stars 91 forks source link

Carousel position resetting when toggling visibility (display none) #666

Open hybrid897 opened 1 week ago

hybrid897 commented 1 week ago

Describe the bug

My use case is a carousel inside a tab component. After I have traversed images in the carousel, I swap tabs and then swap back, adding a display none to the content that is in the inactive tab.

The position of the carousel seems to reset back to the first item. How can I keep the selected carousel item stable after show/hiding it?

Thank you.

Reproduction

https://stackblitz.com/edit/react-ts-pv5u2i

Traverse carousel item to any but the first, then click the show / hide button to toggle display none, it will reset the carousel back to the first item.

Additional context

No response

fancyapps commented 1 week ago

Hi! The script reads the dimensions of the container to determine which slides to display. Therefore, if the container has no dimensions, it is assumed that there is nothing to display.

hybrid897 commented 1 week ago

Thanks for the reply, I can fix it using absolute / visibility hidden positioning it offscreen + aria-hidden instead of display none.

Would be nice if there was an option to disable this behaviour or remember current slide index, but I imagine it would have other repercussions.