浏览代码

Hide tooltip when closing a modal popup

On certain occasions a help tooltip may remain open after closing a
modal.

To reproduce the issue prior to this fix, hover the mouse over an Edit
Replica modal help icon and press the ESC key.

This fix manually removes any tooltip when closing any modal.
Sergiu Miclea 3 年之前
父节点
当前提交
1fd205d575
共有 1 个文件被更改,包括 12 次插入1 次删除
  1. 12 1
      src/components/ui/Modal/Modal.tsx

+ 12 - 1
src/components/ui/Modal/Modal.tsx

@@ -23,6 +23,7 @@ import KeyboardManager from "@src/utils/KeyboardManager";
 import { ThemeProps } from "@src/components/Theme";
 import { ThemeProps } from "@src/components/Theme";
 import headerBackground from "./images/header-background.png";
 import headerBackground from "./images/header-background.png";
 import headerBackgroundWide from "./images/header-background-wide.png";
 import headerBackgroundWide from "./images/header-background-wide.png";
+import ReactTooltip from "react-tooltip";
 
 
 const headerHeight = 48;
 const headerHeight = 48;
 
 
@@ -132,6 +133,16 @@ class NewModal extends React.Component<Props> {
     window.scroll(0, this.windowScrollY || 0);
     window.scroll(0, this.windowScrollY || 0);
   }
   }
 
 
+  handleRequestClose() {
+    /** Remove existing tooltips. Tooltips are not automatically removed when a modal is closed
+     ** (for example when pressing ESC key while hovering over a tooltip) **/
+    ReactTooltip.hide();
+
+    if (this.props.onRequestClose) {
+      this.props.onRequestClose();
+    }
+  }
+
   @autobind
   @autobind
   positionModal(scrollOffset: number) {
   positionModal(scrollOffset: number) {
     const overlay = this.overlayRef as HTMLDivElement;
     const overlay = this.overlayRef as HTMLDivElement;
@@ -232,7 +243,7 @@ class NewModal extends React.Component<Props> {
         isOpen={this.props.isOpen}
         isOpen={this.props.isOpen}
         contentLabel={this.props.contentLabel || this.props.title}
         contentLabel={this.props.contentLabel || this.props.title}
         style={modalStyle}
         style={modalStyle}
-        onRequestClose={this.props.onRequestClose}
+        onRequestClose={() => this.handleRequestClose()}
         onAfterOpen={() => {
         onAfterOpen={() => {
           this.handleModalOpen();
           this.handleModalOpen();
         }}
         }}