diff --git a/packages/core/src/carousel/Carousel.tsx b/packages/core/src/carousel/Carousel.tsx index 1a0d660f..8c04872d 100644 --- a/packages/core/src/carousel/Carousel.tsx +++ b/packages/core/src/carousel/Carousel.tsx @@ -30,6 +30,12 @@ const CarouselRoot = ({ itemsCount, firstVisibleIndex, lastVisibleIndex, + isDragging, + setIsDragging, + handleMouseDown, + handleMouseUp, + debounceMouseDown, + debounceMouseUp, } = withHorizontalScroll({ scrollStep: step || 5, scrollTo: scrollTo, @@ -37,22 +43,26 @@ const CarouselRoot = ({ isRtl, }); - useInterval(() => { - if (!autoSlideDelay) return; - if (isRtl) { - if (canScrollLeft) { - scrollLeftToStep(); + useInterval( + () => { + if (!autoSlideDelay) return; + if (isRtl) { + if (canScrollLeft) { + scrollLeftToStep(); + } else { + scrollToIndex(itemsCount - 1); + } } else { - scrollToIndex(itemsCount - 1); + if (canScrollRight) { + scrollRightToStep(); + } else { + scrollToIndex(0); + } } - } else { - if (canScrollRight) { - scrollRightToStep(); - } else { - scrollToIndex(0); - } - } - }, autoSlideDelay as number); + }, + autoSlideDelay as number, + isDragging, + ); useEffect(() => { if (selectedIndex !== undefined) { @@ -76,6 +86,12 @@ const CarouselRoot = ({ autoSlideDelay, isSwipeDragDisabled: isSwipeDragDisabled ?? false, isRtl, + isDragging, + setIsDragging, + handleMouseDown, + handleMouseUp, + debounceMouseDown, + debounceMouseUp, }} >
@@ -95,10 +111,20 @@ const CarouselRoot = ({ }; const Reel = ({ children, className, ...rest }: SubcomponentProps) => { - const { containerRef, isSwipeDragDisabled, isRtl } = - useCarouselContext("Carousel.Reel"); + const { + containerRef, + isSwipeDragDisabled, + isRtl, + handleMouseDown, + handleMouseUp, + debounceMouseDown, + debounceMouseUp, + } = useCarouselContext("Carousel.Reel"); const arrayChildren = Children.toArray(children); const revertChildren = arrayChildren.reverse(); + const debouncedMouseDown = debounceMouseDown ? debounceMouseDown() : null; + const debouncedMouseUp = debounceMouseUp ? debounceMouseUp() : null; + return (