From 9e7199c7a8b127137bdcdb26e8186b20abc99ec0 Mon Sep 17 00:00:00 2001 From: Ted Brownlow Date: Thu, 7 Jul 2022 14:32:04 -0400 Subject: [PATCH] Fix slide direction for two items --- src/components/CarouselItem.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/components/CarouselItem.tsx b/src/components/CarouselItem.tsx index 0470776..63b1b53 100644 --- a/src/components/CarouselItem.tsx +++ b/src/components/CarouselItem.tsx @@ -111,7 +111,7 @@ export const CarouselItem = ({ animation, next, prev, swipe, state, index, maxIn let animate = 'center'; if (index === active) animate = 'center'; - else if (index === prevActive) + else if (maxIndex>1 && index === prevActive) { animate = isNext ? 'leftwardExit' : 'rightwardExit'; if (active === maxIndex && index === 0) animate = 'rightwardExit'; @@ -120,8 +120,10 @@ export const CarouselItem = ({ animation, next, prev, swipe, state, index, maxIn else { animate = index < active ? 'leftOut' : 'rightOut'; - if (active === maxIndex && index === 0) animate = 'rightOut'; - if (active === 0 && index === maxIndex) animate = 'leftOut' + if (maxIndex > 1) { + if (active === maxIndex && index === 0) animate = 'rightOut'; + if (active === 0 && index === maxIndex) animate = 'leftOut'; + } } duration = duration / 1000; @@ -148,4 +150,4 @@ export const CarouselItem = ({ animation, next, prev, swipe, state, index, maxIn ) -} \ No newline at end of file +}