Browse Source

fix: Remove resize event listening in non-display state of Tooltip (#2606)

* fix: Remove resize event listening in non-display state of Tooltip

* fix: [Tooltip] When visible is false, the resize event does not perform position calculation

---------

Co-authored-by: pointhalo <[email protected]>
YyumeiZhang 10 months ago
parent
commit
3e4437ad50
1 changed files with 5 additions and 1 deletions
  1. 5 1
      packages/semi-foundation/tooltip/foundation.ts

+ 5 - 1
packages/semi-foundation/tooltip/foundation.ts

@@ -191,7 +191,7 @@ export default class Tooltip<P = Record<string, any>, S = Record<string, any>> e
         }
         }
     }
     }
 
 
-    updateStateIfCursorOnTrigger = (trigger: HTMLElement)=>{
+    updateStateIfCursorOnTrigger = (trigger: HTMLElement) => {
         if (trigger?.matches?.(":hover")) {
         if (trigger?.matches?.(":hover")) {
             const eventNames = this._adapter.getEventName();
             const eventNames = this._adapter.getEventName();
             const triggerEventSet = this.getState("triggerEventSet");
             const triggerEventSet = this.getState("triggerEventSet");
@@ -284,6 +284,10 @@ export default class Tooltip<P = Record<string, any>, S = Record<string, any>> e
     onResize = () => {
     onResize = () => {
         // this.log('resize');
         // this.log('resize');
         // rePosition when window resize
         // rePosition when window resize
+        const visible = this.getState('visible');
+        if (!visible) {
+            return;
+        }
         this.calcPosition();
         this.calcPosition();
     };
     };