From 7781eede43be5fa277305ce9bd51bfc6a2a6ff46 Mon Sep 17 00:00:00 2001
From: crupest <crupest@outlook.com>
Date: Wed, 12 Jul 2023 15:17:31 +0800
Subject: Fix dialog overlay click bug.

---
 FrontEnd/src/views/common/dialog/Dialog.tsx | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

(limited to 'FrontEnd/src/views/common/dialog/Dialog.tsx')

diff --git a/FrontEnd/src/views/common/dialog/Dialog.tsx b/FrontEnd/src/views/common/dialog/Dialog.tsx
index c755950d..923c636b 100644
--- a/FrontEnd/src/views/common/dialog/Dialog.tsx
+++ b/FrontEnd/src/views/common/dialog/Dialog.tsx
@@ -1,17 +1,23 @@
-import * as React from "react";
+import { ReactNode } from "react";
 import ReactDOM from "react-dom";
 import { CSSTransition } from "react-transition-group";
 
 import "./Dialog.css";
 
-export interface DialogProps {
+const optionalPortalElement = document.getElementById("portal");
+if (optionalPortalElement == null) {
+  throw new Error("Portal element not found");
+}
+const portalElement = optionalPortalElement;
+
+interface DialogProps {
   onClose: () => void;
   open: boolean;
-  children?: React.ReactNode;
+  children?: ReactNode;
   disableCloseOnClickOnOverlay?: boolean;
 }
 
-export default function Dialog(props: DialogProps): React.ReactElement | null {
+export default function Dialog(props: DialogProps) {
   const { open, onClose, children, disableCloseOnClickOnOverlay } = props;
 
   return ReactDOM.createPortal(
@@ -24,7 +30,7 @@ export default function Dialog(props: DialogProps): React.ReactElement | null {
     >
       <div
         className="cru-dialog-overlay"
-        onClick={
+        onPointerDown={
           disableCloseOnClickOnOverlay
             ? undefined
             : () => {
@@ -34,13 +40,12 @@ export default function Dialog(props: DialogProps): React.ReactElement | null {
       >
         <div
           className="cru-dialog-container"
-          onClick={(e) => e.stopPropagation()}
+          onPointerDown={(e) => e.stopPropagation()}
         >
           {children}
         </div>
       </div>
     </CSSTransition>,
-    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-    document.getElementById("portal")!
+    portalElement,
   );
 }
-- 
cgit v1.2.3

