From 973df5d245afbc12d045d67e3205d8718ff5f284 Mon Sep 17 00:00:00 2001 From: Warrick Corfe-Tan Date: Tue, 20 Jul 2021 14:46:19 +1000 Subject: [PATCH] clicking outside of confirmation modal body closes confirmation modal. --- ts/components/session/SessionConfirm.tsx | 3 - ts/components/session/SessionWrapperModal.tsx | 78 ++++++++++--------- 2 files changed, 42 insertions(+), 39 deletions(-) diff --git a/ts/components/session/SessionConfirm.tsx b/ts/components/session/SessionConfirm.tsx index 190c11632..3fc51d325 100644 --- a/ts/components/session/SessionConfirm.tsx +++ b/ts/components/session/SessionConfirm.tsx @@ -1,13 +1,10 @@ import React, { useState } from 'react'; -import { SessionModal } from './SessionModal'; import { SessionButton, SessionButtonColor } from './SessionButton'; import { SessionHtmlRenderer } from './SessionHTMLRenderer'; import { SessionIcon, SessionIconSize, SessionIconType } from './icon'; import { DefaultTheme, useTheme, withTheme } from 'styled-components'; import { SessionWrapperModal } from './SessionWrapperModal'; -import { useDispatch } from 'react-redux'; import { updateConfirmModal } from '../../state/ducks/modalDialog'; -import { update } from 'lodash'; import { SpacerLG } from '../basic/Text'; import { SessionSpinner } from './SessionSpinner'; diff --git a/ts/components/session/SessionWrapperModal.tsx b/ts/components/session/SessionWrapperModal.tsx index bc0abea83..8a706725b 100644 --- a/ts/components/session/SessionWrapperModal.tsx +++ b/ts/components/session/SessionWrapperModal.tsx @@ -1,4 +1,4 @@ -import React, { useEffect } from 'react'; +import React, { useEffect, useRef } from 'react'; import classNames from 'classnames'; import { SessionIconButton, SessionIconSize, SessionIconType } from './icon/'; @@ -7,27 +7,7 @@ import { DefaultTheme, useTheme } from 'styled-components'; // tslint:disable-next-line: no-submodule-imports import useKey from 'react-use/lib/useKey'; - -type Props = { - title: string; - onClose: any; - showExitIcon?: boolean; - showHeader?: boolean; - headerReverse?: boolean; - //Maximum of two icons or buttons in header - headerIconButtons?: Array<{ - iconType: SessionIconType; - iconRotation: number; - onClick?: any; - }>; - headerButtons?: Array<{ - buttonType: SessionButtonType; - buttonColor: SessionButtonColor; - text: string; - onClick?: any; - }>; - theme: DefaultTheme; -}; +import { nodeName } from 'jquery'; export type SessionWrapperModalType = { title?: string; @@ -79,10 +59,36 @@ export const SessionWrapperModal = (props: SessionWrapperModalType) => { [props.onClose] ); + const modalRef = useRef(null); + + const handleClick = (e: any) => { + if (!modalRef.current?.contains(e.target)) { + console.log('clicked outside of modal'); + props.onClose?.(); + } + } + + useEffect(() => { + // on mount + document.addEventListener("mousedown", handleClick); + + // unmount + return () => { + document.removeEventListener("mousedown", handleClick); + } + }, []) + return ( -
-
-
+
+
+
{showHeader ? (
@@ -99,17 +105,17 @@ export const SessionWrapperModal = (props: SessionWrapperModalType) => {
{headerIconButtons ? headerIconButtons.map((iconItem: any) => { - return ( - - ); - }) + return ( + + ); + }) : null}