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 9d65b40
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 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,
};
16 changes: 7 additions & 9 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,8 @@ 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(() => {
slide(SlideDirection.Right);
}, props.autoSwipe);
}
};
Expand Down Expand Up @@ -254,18 +252,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 9d65b40

Please sign in to comment.