diff options
author | crupest <crupest@outlook.com> | 2023-07-12 15:25:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-12 15:25:15 +0800 |
commit | 4a069bf1268f393d5467166356f691eb89963152 (patch) | |
tree | 1bfa25fda4bd970a609c161b18e6616b5d5e8221 /FrontEnd/src/views/common/dialog | |
parent | 78f0934815a87573289c8e52af2666ea38c93251 (diff) | |
parent | 7781eede43be5fa277305ce9bd51bfc6a2a6ff46 (diff) | |
download | timeline-4a069bf1268f393d5467166356f691eb89963152.tar.gz timeline-4a069bf1268f393d5467166356f691eb89963152.tar.bz2 timeline-4a069bf1268f393d5467166356f691eb89963152.zip |
Merge pull request #1386 from crupest/dev
Develop.
Diffstat (limited to 'FrontEnd/src/views/common/dialog')
-rw-r--r-- | FrontEnd/src/views/common/dialog/Dialog.tsx | 21 |
1 files changed, 13 insertions, 8 deletions
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, ); } |