htmlstreamofficial / preline

Preline UI is an open-source set of prebuilt UI components based on the utility-first Tailwind CSS framework.
https://preline.co
Other
4.88k stars 307 forks source link

BUG: Carousel doesn't work when placed unter tab navigation #392

Closed coolusaHD closed 4 months ago

coolusaHD commented 5 months ago

Summary

Carousel doesn't work when placed unter tab navigation.

Steps to Reproduce

  1. Open Demo
  2. Run
  3. Click trough the tab navigation

image

Demo Link

https://stackblitz.com/edit/withastro-astro-fzqgqu?file=src%2Fpages%2Findex.astro

Expected Behavior

No response

Actual Behavior

No response

Screenshots

No response

olegpix commented 4 months ago

Summary

Carousel doesn't work when placed unter tab navigation.

Steps to Reproduce

  1. Open Demo
  2. Run
  3. Click trough the tab navigation

image

Demo Link

https://stackblitz.com/edit/withastro-astro-fzqgqu?file=src%2Fpages%2Findex.astro

Expected Behavior

No response

Actual Behavior

No response

Screenshots

No response

Hi, You need to recalculate the carousel width every time you change tab (check the full code in the demo)

<script type="module">
  window.addEventListener('load', () => {
    const tabs = HSTabs.getInstance("#tabs-01", true);
    tabs.element.on('change', ({ current }) => {
      const carousel = HSCarousel.getInstance(`${current} [data-hs-carousel]`, true);
      carousel.element.recalculateWidth();
    });
  });
</script>