From d6a2e9be3d39347c3c52378f3a3f62567272a75d Mon Sep 17 00:00:00 2001 From: nklhrstv Date: Fri, 14 Feb 2020 11:43:04 +0200 Subject: [PATCH 1/2] close modal dialogs on resize dropped --- src/common/ModalDialog/ModalDialog.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/common/ModalDialog/ModalDialog.js b/src/common/ModalDialog/ModalDialog.js index affe7dd35..a5170b08e 100644 --- a/src/common/ModalDialog/ModalDialog.js +++ b/src/common/ModalDialog/ModalDialog.js @@ -34,15 +34,6 @@ const ModalDialog = ({ className, title, buttons, children, dataset, onCloseRequ event.nativeEvent.closeModalDialogPrevented = true; }, []); React.useEffect(() => { - const onWindowResize = (event) => { - if (typeof onCloseRequest === 'function') { - onCloseRequest({ - type: 'close', - dataset: dataset, - nativeEvent: event - }); - } - }; const onWindowKeyDown = (event) => { // its `-2` because focus lock render locking divs around its content if (modalsContainer.childNodes[modalsContainer.childElementCount - 2] === modalContainerRef.current) { @@ -55,10 +46,8 @@ const ModalDialog = ({ className, title, buttons, children, dataset, onCloseRequ } } }; - window.addEventListener('resize', onWindowResize); window.addEventListener('keydown', onWindowKeyDown); return () => { - window.removeEventListener('resize', onWindowResize); window.removeEventListener('keydown', onWindowKeyDown); }; }, [dataset, onCloseRequest]); From c231a648e83ac971759964efdb1fe7436112c841 Mon Sep 17 00:00:00 2001 From: nklhrstv Date: Fri, 14 Feb 2020 11:44:18 +0200 Subject: [PATCH 2/2] close modal dialog only on Esc button --- src/common/ModalDialog/ModalDialog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/ModalDialog/ModalDialog.js b/src/common/ModalDialog/ModalDialog.js index a5170b08e..0ec3360ef 100644 --- a/src/common/ModalDialog/ModalDialog.js +++ b/src/common/ModalDialog/ModalDialog.js @@ -36,7 +36,7 @@ const ModalDialog = ({ className, title, buttons, children, dataset, onCloseRequ React.useEffect(() => { const onWindowKeyDown = (event) => { // its `-2` because focus lock render locking divs around its content - if (modalsContainer.childNodes[modalsContainer.childElementCount - 2] === modalContainerRef.current) { + if (event.key === 'Escape' && modalsContainer.childNodes[modalsContainer.childElementCount - 2] === modalContainerRef.current) { if (typeof onCloseRequest === 'function') { onCloseRequest({ type: 'close',