Skip to content

Commit

Permalink
Round numbers to fix page indicator and scrolling bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
melvin-chen committed Mar 1, 2024
1 parent 495b25f commit c2e59d2
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/nuka/src/Carousel/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,10 @@ export const Carousel = forwardRef<SlideHandle, CarouselProps>(

useEffect(() => {
const handleDebounce = setTimeout(() => {
setCurrentScrollIndex(currentManualScrollIndex);

const roundedManualScrollIndex = Math.round(currentManualScrollIndex);
const closestPassedSlide = pageStartIndices.reduce(
(prev, current, index) =>
current - currentManualScrollIndex < 0 ? index + 1 : prev,
current - roundedManualScrollIndex < 0 ? index + 1 : prev,
0
);
setCurrentSlideIndex(closestPassedSlide);
Expand Down Expand Up @@ -210,7 +209,7 @@ export const Carousel = forwardRef<SlideHandle, CarouselProps>(
? 0
: findLastIndex(
pageStartIndices,
(index) => containerScrollDistance >= index
(index) => Math.round(containerScrollDistance) >= index
);
}
return 0;
Expand Down

0 comments on commit c2e59d2

Please sign in to comment.