Browse Source

fix: [carousel] Fix the problem that the timer is not updated when carousel switches the index through the left and right buttons or methods (#1165)

Co-authored-by: pointhalo <[email protected]>
YyumeiZhang 3 years ago
parent
commit
b82bd23183
1 changed files with 4 additions and 0 deletions
  1. 4 0
      packages/semi-foundation/carousel/foundation.ts

+ 4 - 0
packages/semi-foundation/carousel/foundation.ts

@@ -47,6 +47,7 @@ class CarouselFoundation<P = Record<string, any>, S = Record<string, any>> exten
     }
 
     next(): void {
+        this.stop();
         const { activeIndex: stateActiveIndex } = this.getStates();
         const targetIndex = this.getValidIndex(stateActiveIndex + 1);
         this._adapter.setIsReverse(false);
@@ -56,9 +57,11 @@ class CarouselFoundation<P = Record<string, any>, S = Record<string, any>> exten
             this._notifyChange(targetIndex);
             this.handleNewActiveIndex(targetIndex);
         }
+        this.handleAutoPlay();
     }
 
     prev(): void {
+        this.stop();
         const { activeIndex: stateActiveIndex } = this.getStates();
         const targetIndex = this.getValidIndex(stateActiveIndex - 1);
         this._adapter.setIsReverse(true);
@@ -68,6 +71,7 @@ class CarouselFoundation<P = Record<string, any>, S = Record<string, any>> exten
             this._notifyChange(targetIndex);
             this.handleNewActiveIndex(targetIndex);
         }
+        this.handleAutoPlay();
     }
 
     destroy(): void {