Skip to content

Commit

Permalink
feat(carousel): add support to turn off interval
Browse files Browse the repository at this point in the history
Closes #804
  • Loading branch information
jiverson authored and pkozlowski-opensource committed Sep 28, 2016
1 parent a173e40 commit c5625e8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/carousel/carousel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,29 @@ describe('ngb-carousel', () => {
discardPeriodicTasks();
}));

it('should not change slide on time passage (custom interval value is zero)', fakeAsync(() => {
const html = `
<ngb-carousel [interval]="0">
<template ngbSlide>foo</template>
<template ngbSlide>bar</template>
</ngb-carousel>
`;

const fixture = createTestComponent(html);

expectActiveSlides(fixture.nativeElement, [true, false]);

tick(1000);
fixture.detectChanges();
expectActiveSlides(fixture.nativeElement, [true, false]);

tick(1200);
fixture.detectChanges();
expectActiveSlides(fixture.nativeElement, [true, false]);

discardPeriodicTasks();
}));

it('should pause / resume slide change with time passage on mouse enter / leave', fakeAsync(() => {
const html = `
<ngb-carousel>
Expand Down
4 changes: 3 additions & 1 deletion src/carousel/carousel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ export class NgbCarousel implements AfterContentChecked,
}

private _startTimer() {
this._slideChangeInterval = setInterval(() => { this.cycleToNext(); }, this.interval);
if (this.interval > 0) {
this._slideChangeInterval = setInterval(() => { this.cycleToNext(); }, this.interval);
}
}

private _stopTimer() { clearInterval(this._slideChangeInterval); }
Expand Down

0 comments on commit c5625e8

Please sign in to comment.