@@ -98,6 +98,7 @@ const Carousel = forwardRef<CarouselRef, CarouselProps>(
9898 const [ dragStart , setDragStart ] = useState ( {
9999 x : 0 ,
100100 y : 0 ,
101+ timestamp : 0 ,
101102 } ) ;
102103 const [ dragging , setDragging ] = useState ( false ) ;
103104 const [ scrolling , setScrolling ] = useState ( false ) ;
@@ -207,7 +208,7 @@ const Carousel = forwardRef<CarouselRef, CarouselProps>(
207208 clearInterval ( autoPlayIntervalRef . current ) ;
208209 }
209210
210- setDragStart ( { x : clientX , y : clientY } ) ;
211+ setDragStart ( { x : clientX , y : clientY , timestamp : Date . now ( ) } ) ;
211212 } , [ ] ) ;
212213
213214 const handleDragMove = useCallback (
@@ -264,9 +265,15 @@ const Carousel = forwardRef<CarouselRef, CarouselProps>(
264265
265266 // Determine the new slide index based on drag offset
266267 let newSlide = currentSlide ;
267- if ( dragOffset > containerWidth / 2 ) {
268+ if (
269+ dragOffset > containerWidth / 2 ||
270+ ( Date . now ( ) - dragStart . timestamp < 200 && dragOffset > 20 )
271+ ) {
268272 newSlide = Math . max ( 0 , currentSlide - 1 ) ;
269- } else if ( dragOffset < - containerWidth / 2 ) {
273+ } else if (
274+ dragOffset < - containerWidth / 2 ||
275+ ( Date . now ( ) - dragStart . timestamp < 200 && dragOffset < - 20 )
276+ ) {
270277 newSlide = Math . min ( slides - shownSlides , currentSlide + 1 ) ;
271278 }
272279
@@ -298,7 +305,7 @@ const Carousel = forwardRef<CarouselRef, CarouselProps>(
298305 if ( ! disableTranslate ) {
299306 return {
300307 transform : `translateX(${ - translateX } px)` ,
301- transitionDuration : `${ dragging ? 0.01 : transitionDuration } s` ,
308+ transitionDuration : `${ dragging ? 0.005 : transitionDuration } s` ,
302309 transitionTimingFunction : dragging ? "linear" : undefined ,
303310 height : fitHeight ? "fit-content" : undefined ,
304311 } ;
0 commit comments