From 0038c2225b6ecbe9464adacb83ac93f70f297afd Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Thu, 26 Oct 2023 11:16:34 +0800 Subject: [PATCH] Fix 1 more esc clash --- src/components/compose.jsx | 8 ++++++++ src/components/modal.jsx | 9 +++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/components/compose.jsx b/src/components/compose.jsx index e4fcf69c..14d2990a 100644 --- a/src/components/compose.jsx +++ b/src/components/compose.jsx @@ -387,6 +387,14 @@ function Compose({ enableOnFormTags: true, // Use keyup because Esc keydown will close the confirm dialog on Safari keyup: true, + ignoreEventWhen: (e) => { + const modals = document.querySelectorAll('#modal-container > *'); + const hasModal = !!modals; + const hasOnlyComposer = + modals.length === 1 && modals[0].querySelector('#compose-container'); + console.log('hasModal', hasModal, 'hasOnlyComposer', hasOnlyComposer); + return hasModal && !hasOnlyComposer; + }, }, ); diff --git a/src/components/modal.jsx b/src/components/modal.jsx index dfe7b535..d9ba635d 100644 --- a/src/components/modal.jsx +++ b/src/components/modal.jsx @@ -22,12 +22,17 @@ function Modal({ children, onClose, onClick, class: className }) { const escRef = useHotkeys( 'esc', - onClose, + () => { + setTimeout(() => { + onClose?.(); + }, 0); + }, { enabled: !!onClose, + // Using keyup and setTimeout above + // This will run "later" to prevent clash with esc handlers from other components keydown: false, keyup: true, - // This will run "later" to prevent clash with esc handlers from other components }, [onClose], );