Skip to content

Commit

Permalink
fix(carousel): implement auto slide without DOM focus interference
Browse files Browse the repository at this point in the history
  • Loading branch information
Mert Can Altin committed Sep 3, 2024
1 parent bef4a18 commit 8033f2e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/components/carousel/defaultProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ export const defaultProps: Required<CarouselProps> = {
triggerClickOn: Number.MIN_SAFE_INTEGER,
hideArrows: false,
onLeftArrowClick: () => null,
onRightArrowClick: () => null
onRightArrowClick: () => null,
};
19 changes: 11 additions & 8 deletions src/components/carousel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const Carousel: FunctionComponent<CarouselProps> = (userProps: CarouselPr
const [page, setPage] = useState<number>(0);
const isPaginating = useRef(false);
const slideButtonRef = useRef<HTMLDivElement>(null);
const autoSwipeTimer = useRef<number>();
const autoSwipeTimer = useRef<number>(0);
const isNavigation = typeof props.navigation === 'function';

if (props.dynamic) {
Expand Down Expand Up @@ -93,10 +93,13 @@ export const Carousel: FunctionComponent<CarouselProps> = (userProps: CarouselPr
typeof props.autoSwipe === 'number' &&
props.autoSwipe > props.transition
) {
autoSwipeTimer.current = setTimeout(() => {
if (slideButtonRef.current) {
slideButtonRef.current!.click();
autoSwipeTimer.current = window.setTimeout(() => {
if (showArrow.right) {
slide(SlideDirection.Right);
} else {
slide(SlideDirection.Left);
}
autoSwipe();
}, props.autoSwipe);
}
};
Expand Down Expand Up @@ -254,18 +257,18 @@ export const Carousel: FunctionComponent<CarouselProps> = (userProps: CarouselPr
};

const onLeftArrowClick = () => {
slide(SlideDirection.Left)
slide(SlideDirection.Left);
if (props.onLeftArrowClick) {
props.onLeftArrowClick();
}
}
};

const onRightArrowClick = () => {
slide(SlideDirection.Right)
slide(SlideDirection.Right);
if (props.onRightArrowClick) {
props.onRightArrowClick();
}
}
};

return (
<div
Expand Down

0 comments on commit 8033f2e

Please sign in to comment.