@@ -14,6 +14,8 @@ import * as telemetry from '../../common/telemetry';
14
14
import CarouselImage from "./CarouselImage" ;
15
15
16
16
export class Carousel extends React . Component < ICarouselProps , ICarouselState > {
17
+ private _intervalId : number | undefined ;
18
+
17
19
constructor ( props : ICarouselProps ) {
18
20
super ( props ) ;
19
21
@@ -42,9 +44,15 @@ export class Carousel extends React.Component<ICarouselProps, ICarouselState> {
42
44
this . setState ( {
43
45
processingState : ProcessingState . idle
44
46
} ) ;
47
+ this . startCycle ( ) ; // restarting cycle when new slide is available
45
48
}
46
49
}
47
50
51
+ public componentDidMount ( ) {
52
+ // starting auto cycling
53
+ this . startCycle ( ) ;
54
+ }
55
+
48
56
49
57
public render ( ) : React . ReactElement < ICarouselProps > {
50
58
const { currentIndex, processingState } = this . state ;
@@ -192,6 +200,9 @@ export class Carousel extends React.Component<ICarouselProps, ICarouselState> {
192
200
}
193
201
194
202
private onIndicatorClick = ( e : React . MouseEvent < HTMLElement > | React . TouchEvent < HTMLElement > , index : number ) : void => {
203
+
204
+ this . startCycle ( ) ;
205
+
195
206
if ( this . props . onSelect ) {
196
207
this . props . onSelect ( index ) ;
197
208
}
@@ -296,6 +307,9 @@ export class Carousel extends React.Component<ICarouselProps, ICarouselState> {
296
307
* Handles carousel button click.
297
308
*/
298
309
private onCarouselButtonClicked = ( nextButtonClicked : boolean ) : void => {
310
+
311
+ this . startCycle ( ) ;
312
+
299
313
const currentIndex = this . state . currentIndex ;
300
314
301
315
let nextIndex = this . state . currentIndex ;
@@ -406,4 +420,47 @@ export class Carousel extends React.Component<ICarouselProps, ICarouselState> {
406
420
407
421
return result ;
408
422
}
423
+
424
+ private startCycle = ( ) : void => {
425
+
426
+ const {
427
+ interval,
428
+ triggerPageEvent
429
+ } = this . props ;
430
+
431
+ if ( this . _intervalId ) {
432
+ if ( triggerPageEvent ) {
433
+ clearTimeout ( this . _intervalId ) ;
434
+ }
435
+ else {
436
+ clearInterval ( this . _intervalId ) ;
437
+ }
438
+ }
439
+
440
+ if ( interval !== null ) {
441
+ const intervalValue = interval || 5000 ;
442
+ if ( ! triggerPageEvent ) {
443
+ this . _intervalId = setInterval ( this . moveNext , intervalValue ) ;
444
+ }
445
+ else {
446
+ this . _intervalId = setTimeout ( this . moveNext , intervalValue ) ;
447
+ }
448
+ }
449
+ }
450
+
451
+ private moveNext = ( ) : void => {
452
+ if ( ! this . isCarouselButtonDisabled ( true ) ) {
453
+ this . onCarouselButtonClicked ( true ) ;
454
+ }
455
+ else {
456
+ if ( this . _intervalId ) {
457
+ if ( this . props . triggerPageEvent ) {
458
+ clearTimeout ( this . _intervalId ) ;
459
+ }
460
+ else {
461
+ clearInterval ( this . _intervalId ) ;
462
+ }
463
+ }
464
+ }
465
+ }
409
466
}
0 commit comments