Skip to content

Commit 8033f2e

Browse files
author
Mert Can Altin
committed
fix(carousel): implement auto slide without DOM focus interference
1 parent bef4a18 commit 8033f2e

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/components/carousel/defaultProps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ export const defaultProps: Required<CarouselProps> = {
2222
triggerClickOn: Number.MIN_SAFE_INTEGER,
2323
hideArrows: false,
2424
onLeftArrowClick: () => null,
25-
onRightArrowClick: () => null
25+
onRightArrowClick: () => null,
2626
};

src/components/carousel/index.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const Carousel: FunctionComponent<CarouselProps> = (userProps: CarouselPr
5555
const [page, setPage] = useState<number>(0);
5656
const isPaginating = useRef(false);
5757
const slideButtonRef = useRef<HTMLDivElement>(null);
58-
const autoSwipeTimer = useRef<number>();
58+
const autoSwipeTimer = useRef<number>(0);
5959
const isNavigation = typeof props.navigation === 'function';
6060

6161
if (props.dynamic) {
@@ -93,10 +93,13 @@ export const Carousel: FunctionComponent<CarouselProps> = (userProps: CarouselPr
9393
typeof props.autoSwipe === 'number' &&
9494
props.autoSwipe > props.transition
9595
) {
96-
autoSwipeTimer.current = setTimeout(() => {
97-
if (slideButtonRef.current) {
98-
slideButtonRef.current!.click();
96+
autoSwipeTimer.current = window.setTimeout(() => {
97+
if (showArrow.right) {
98+
slide(SlideDirection.Right);
99+
} else {
100+
slide(SlideDirection.Left);
99101
}
102+
autoSwipe();
100103
}, props.autoSwipe);
101104
}
102105
};
@@ -254,18 +257,18 @@ export const Carousel: FunctionComponent<CarouselProps> = (userProps: CarouselPr
254257
};
255258

256259
const onLeftArrowClick = () => {
257-
slide(SlideDirection.Left)
260+
slide(SlideDirection.Left);
258261
if (props.onLeftArrowClick) {
259262
props.onLeftArrowClick();
260263
}
261-
}
264+
};
262265

263266
const onRightArrowClick = () => {
264-
slide(SlideDirection.Right)
267+
slide(SlideDirection.Right);
265268
if (props.onRightArrowClick) {
266269
props.onRightArrowClick();
267270
}
268-
}
271+
};
269272

270273
return (
271274
<div

0 commit comments

Comments
 (0)