From 4e5e2fa75ffcc872ecf9d001ca1d41ce57ecc27f Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Wed, 8 Mar 2023 14:49:52 +0800 Subject: [PATCH] Fix esc triggering exit confirmation when closing the expander --- src/components/compose.jsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/compose.jsx b/src/components/compose.jsx index 0eafecf0..96ab80da 100644 --- a/src/components/compose.jsx +++ b/src/components/compose.jsx @@ -348,12 +348,24 @@ function Compose({ }; useEffect(updateCharCount, []); + const escDownRef = useRef(false); useHotkeys( 'esc', () => { - if (!standalone && confirmClose()) { + escDownRef.current = true; + // This won't be true if this event is already handled and not propagated 🤞 + }, + { + enableOnFormTags: true, + }, + ); + useHotkeys( + 'esc', + () => { + if (!standalone && escDownRef.current && confirmClose()) { onClose(); } + escDownRef.current = false; }, { enableOnFormTags: true,