Fix 'esc' closes both modal and status page

This commit is contained in:
Lim Chee Aun 2023-10-26 02:19:01 +08:00
parent c03f39b10c
commit 81644e67bb
2 changed files with 15 additions and 3 deletions

View file

@ -20,9 +20,17 @@ function Modal({ children, onClose, onClick, class: className }) {
return () => clearTimeout(timer);
}, []);
const escRef = useHotkeys('esc', onClose, [onClose], {
enabled: !!onClose,
});
const escRef = useHotkeys(
'esc',
onClose,
{
enabled: !!onClose,
keydown: false,
keyup: true,
// This will run "later" to prevent clash with esc handlers from other components
},
[onClose],
);
const Modal = (
<div

View file

@ -537,6 +537,10 @@ function StatusThread({ id, closeLink = '/', instance: propInstance }) {
// If media is open, esc to close media first
// Else close the status page
enabled: !showMedia,
ignoreEventWhen: (e) => {
const hasModal = !!document.querySelector('#modal-container > *');
return hasModal;
},
},
);
// For backspace, will always close both media and status page