themesberg / flowbite-react

Official React components built for Flowbite and Tailwind CSS
https://flowbite-react.com
MIT License
1.86k stars 417 forks source link

Setting Active Image In the Slider #1094

Open technotip opened 11 months ago

technotip commented 11 months ago

We can programatically set the active image: https://flowbite.com/docs/components/carousel/#default-slider

But the same is not available in flowbite react: https://www.flowbite-react.com/docs/components/carousel

Can we please get this in React too?

Expected Behaviour: When we set data-carousel-item="active" or something similar on any image, that image should be shown in the carousel and not from index 0.

I am using: import { Carousel } from 'flowbite-react';

technotip commented 11 months ago

I see that setting data-carousel-item="active" does work partially. i.e., the indicator points to the correct active image. But the image itself still shows the 0th index image on the carousel instead of the image which is set as "active".

technotip commented 11 months ago

Expected Changes:

The active={true | false} should be present on all the img tags, which are inside <Carousel></Carousel>. That way the library can pickup the active image to show on the canvas/Carousel and then change the indicators accordingly.

rluders commented 11 months ago

Not sure if adding active={boolean} to every single img or div or whatever content is desirable, instead, the best approach, IMHO, would be to add the activeSlide={number} to the Carousel component.

kurtisdunn commented 9 months ago

Just as a bump, i too was about to use the react comp and ended up making my own from the JS version. Underneath the carousel I wanted to show thumbnails and set state to jump to the active image.

activeSlide={number} would be the best approach here.

xegulon commented 7 months ago

what about a ref that we can use with ref.current.slideTo(index) ?

<Carousel carouselRef={ref} />

cristiantiradob commented 6 months ago

@tulup-conner @rluders hey check this out #1214

ArthurJahn commented 5 months ago

Any updates? Do you guys plan to review/approve #1214 ?

enzoimola commented 3 months ago

Any updates guys?

wellitongervickas commented 1 month ago

Any news?

wellitongervickas commented 1 month ago

Guys, to fix that, I wrote the "REF" in the parent component, and scroll to left using the "item" size. Eg:

  useEffect(() => {
    const slider = carouselParentRef?.current?.children?.[0]?.children?.[0]
    if (slider) {
      slider.scrollLeft = activeSliderIndex * colsSize.width
    }
  }, [activeSliderIndex, colsSize.width])