From 2e9489fa22acc6c79fd6bf8830ffa55146acd463 Mon Sep 17 00:00:00 2001 From: Giorgio Boa <35845425+gioboa@users.noreply.github.com> Date: Wed, 5 Jun 2019 21:10:33 +0200 Subject: [PATCH] Fix/carousel reset time out #5201 (#5235) * fix: carousel: restart timer after slide selection Close: #5201 #4853 --- src/carousel/carousel.component.ts | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/carousel/carousel.component.ts b/src/carousel/carousel.component.ts index a16c2cf5c1..082b3654a6 100644 --- a/src/carousel/carousel.component.ts +++ b/src/carousel/carousel.component.ts @@ -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); } @@ -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); } @@ -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 { @@ -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, @@ -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'); @@ -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; @@ -617,7 +631,7 @@ export class CarouselComponent implements AfterViewInit, OnDestroy { nInterval > 0 && this.slides.length ) { - this.nextSlide(); + this.nextSlideFromInterval(); } else { this.pause(); }