Skip to content

Commit ca0b43e

Browse files
committed
feat: Stop advancing if user presses one of the Carousel buttons
1 parent 0151bd1 commit ca0b43e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/test-case-component/src/components/shikiComponent.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,32 +80,39 @@ const STEP_DURATIONS = [1500, 500, 1500]; // milliseconds
8080

8181
function Carousel({ children }: { children: React.ReactNode[] }) {
8282
const [activeIndex, setActiveIndex] = useState(0);
83+
const [paused, setPaused] = useState(false);
8384

8485
const handleNext = () => {
8586
setActiveIndex((prevIndex) => (prevIndex + 1) % children.length);
87+
setPaused(true); // Pause on manual navigation
8688
};
8789

8890
const handlePrev = () => {
8991
setActiveIndex((prevIndex) =>
9092
prevIndex === 0 ? children.length - 1 : prevIndex - 1,
9193
);
94+
setPaused(true); // Pause on manual navigation
9295
};
9396

9497
const handleIndicatorClick = (index: number) => {
9598
setActiveIndex(index);
99+
setPaused(true); // Pause on manual navigation
96100
};
97101

98102
const timeoutRef = useRef<any>(null);
99103

100104
useEffect(() => {
105+
if (paused) {
106+
return; // Don't auto-rotate if paused
107+
}
101108
const duration = STEP_DURATIONS[activeIndex] || 3000;
102109

103110
timeoutRef.current = setTimeout(() => {
104111
setActiveIndex((prevIndex) => (prevIndex + 1) % children.length);
105112
}, duration);
106113

107114
return () => clearTimeout(timeoutRef.current);
108-
}, [activeIndex, children.length]);
115+
}, [activeIndex, children.length, paused]);
109116

110117
const CarouselItem = ({
111118
child,

0 commit comments

Comments
 (0)