Ver código fonte

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

Co-authored-by: zwlafk <[email protected]>
zwlafk 3 anos atrás
pai
commit
06d9a0446e
1 arquivos alterados com 9 adições e 2 exclusões
  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;
 
+    _notifyChange(activeKey: string): void {
+        const { activeKey: stateActiveKey } = this.getStates();
+        if (stateActiveKey !== activeKey) {
+            this._adapter.notifyChange(activeKey);
+        }
+    }
+
     handleTabClick(activeKey: string, event: any): void {
         const isControledComponent = this._isInProps('activeKey');
         if (isControledComponent) {
-            this._adapter.notifyChange(activeKey);
+            this._notifyChange(activeKey);
         } else {
-            this._adapter.notifyChange(activeKey);
+            this._notifyChange(activeKey);
             this.handleNewActiveKey(activeKey);
         }
         this._adapter.notifyTabClick(activeKey, event);