ui icon indicating copy to clipboard operation
ui copied to clipboard

Carousel position resetting when toggling visibility (display none)

Open hybrid897 opened this issue 1 year ago • 2 comments

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

hybrid897 avatar Jun 21 '24 07:06 hybrid897

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.

fancyapps avatar Jun 21 '24 07:06 fancyapps

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.

hybrid897 avatar Jun 21 '24 08:06 hybrid897

This has been fixed in the latest update. Demo - https://jsbin.com/bepobavagi/edit?html,output

fancyapps avatar Jul 08 '25 11:07 fancyapps