Bladeren bron

fix(tabs): onChange triggers unexpectly when click active tab (#284)

Co-authored-by: zwlafk <[email protected]>
zwlafk 3 jaren geleden
bovenliggende
commit
06d9a0446e
1 gewijzigde bestanden met toevoegingen van 9 en 2 verwijderingen
  1. 9 2
      packages/semi-foundation/tabs/foundation.ts

+ 9 - 2
packages/semi-foundation/tabs/foundation.ts

@@ -20,12 +20,19 @@ class TabsFoundation<P = Record<string, any>, S = Record<string, any>> extends B
 
 
     destroy = noop;
     destroy = noop;
 
 
+    _notifyChange(activeKey: string): void {
+        const { activeKey: stateActiveKey } = this.getStates();
+        if (stateActiveKey !== activeKey) {
+            this._adapter.notifyChange(activeKey);
+        }
+    }
+
     handleTabClick(activeKey: string, event: any): void {
     handleTabClick(activeKey: string, event: any): void {
         const isControledComponent = this._isInProps('activeKey');
         const isControledComponent = this._isInProps('activeKey');
         if (isControledComponent) {
         if (isControledComponent) {
-            this._adapter.notifyChange(activeKey);
+            this._notifyChange(activeKey);
         } else {
         } else {
-            this._adapter.notifyChange(activeKey);
+            this._notifyChange(activeKey);
             this.handleNewActiveKey(activeKey);
             this.handleNewActiveKey(activeKey);
         }
         }
         this._adapter.notifyTabClick(activeKey, event);
         this._adapter.notifyTabClick(activeKey, event);