Skip to content

Commit

Permalink
Fix/carousel reset time out valor-software#5201 (valor-software#5235)
Browse files Browse the repository at this point in the history
* fix: carousel: restart timer after slide selection Close: valor-software#5201 valor-software#4853
  • Loading branch information
gioboa authored and leo6104 committed Oct 10, 2019
1 parent 436695e commit c291570
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/carousel/carousel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,18 @@ export class CarouselComponent implements AfterViewInit, OnDestroy {
}
}

nextSlideFromInterval(force = false): void {
this.move(Direction.NEXT, force);
}

/**
* Rolling to next slide
* @param force: {boolean} if true - will ignore noWrap flag
*/
nextSlide(force = false): void {
if (this.isPlaying) {
this.restartTimer();
}
this.move(Direction.NEXT, force);
}

Expand All @@ -200,6 +207,9 @@ export class CarouselComponent implements AfterViewInit, OnDestroy {
* @param force: {boolean} if true - will ignore noWrap flag
*/
previousSlide(force = false): void {
if (this.isPlaying) {
this.restartTimer();
}
this.move(Direction.PREV, force);
}

Expand Down Expand Up @@ -240,6 +250,10 @@ export class CarouselComponent implements AfterViewInit, OnDestroy {
* @param index: {number} index of slide, which must be shown
*/
selectSlide(index: number): void {
if (this.isPlaying) {
this.restartTimer();
}

if (!this.multilist) {
this.activeSlide = index;
} else {
Expand Down Expand Up @@ -307,8 +321,8 @@ export class CarouselComponent implements AfterViewInit, OnDestroy {
...this._slidesWithIndexes,
...slidesToAppend
]
.slice(slidesToAppend.length)
.slice(0, this.itemsPerSlide);
.slice(slidesToAppend.length)
.slice(0, this.itemsPerSlide);
} else {
this._slidesWithIndexes = this._slidesWithIndexes.slice(
startIndex,
Expand Down Expand Up @@ -358,8 +372,8 @@ export class CarouselComponent implements AfterViewInit, OnDestroy {
this._currentActiveSlide > 0
? this._currentActiveSlide - 1
: !force && this.noWrap
? this._currentActiveSlide
: this._slides.length - 1;
? this._currentActiveSlide
: this._slides.length - 1;
break;
default:
throw new Error('Unknown direction');
Expand Down Expand Up @@ -477,7 +491,7 @@ export class CarouselComponent implements AfterViewInit, OnDestroy {
indexToShow = direction !== Direction.NEXT
? firstVisibleIndex - 1
: !this.isLast(lastVisibleIndex)
? lastVisibleIndex + 1 : 0;
? lastVisibleIndex + 1 : 0;

this._slides.get(indexToHide).active = false;
this._slides.get(indexToShow).active = true;
Expand Down Expand Up @@ -617,7 +631,7 @@ export class CarouselComponent implements AfterViewInit, OnDestroy {
nInterval > 0 &&
this.slides.length
) {
this.nextSlide();
this.nextSlideFromInterval();
} else {
this.pause();
}
Expand Down

0 comments on commit c291570

Please sign in to comment.