@@ -80,32 +80,39 @@ const STEP_DURATIONS = [1500, 500, 1500]; // milliseconds
80
80
81
81
function Carousel ( { children } : { children : React . ReactNode [ ] } ) {
82
82
const [ activeIndex , setActiveIndex ] = useState ( 0 ) ;
83
+ const [ paused , setPaused ] = useState ( false ) ;
83
84
84
85
const handleNext = ( ) => {
85
86
setActiveIndex ( ( prevIndex ) => ( prevIndex + 1 ) % children . length ) ;
87
+ setPaused ( true ) ; // Pause on manual navigation
86
88
} ;
87
89
88
90
const handlePrev = ( ) => {
89
91
setActiveIndex ( ( prevIndex ) =>
90
92
prevIndex === 0 ? children . length - 1 : prevIndex - 1 ,
91
93
) ;
94
+ setPaused ( true ) ; // Pause on manual navigation
92
95
} ;
93
96
94
97
const handleIndicatorClick = ( index : number ) => {
95
98
setActiveIndex ( index ) ;
99
+ setPaused ( true ) ; // Pause on manual navigation
96
100
} ;
97
101
98
102
const timeoutRef = useRef < any > ( null ) ;
99
103
100
104
useEffect ( ( ) => {
105
+ if ( paused ) {
106
+ return ; // Don't auto-rotate if paused
107
+ }
101
108
const duration = STEP_DURATIONS [ activeIndex ] || 3000 ;
102
109
103
110
timeoutRef . current = setTimeout ( ( ) => {
104
111
setActiveIndex ( ( prevIndex ) => ( prevIndex + 1 ) % children . length ) ;
105
112
} , duration ) ;
106
113
107
114
return ( ) => clearTimeout ( timeoutRef . current ) ;
108
- } , [ activeIndex , children . length ] ) ;
115
+ } , [ activeIndex , children . length , paused ] ) ;
109
116
110
117
const CarouselItem = ( {
111
118
child,
0 commit comments