From 01e467d0699dfc14f68dacf0f843f5c71755220e Mon Sep 17 00:00:00 2001 From: "Tom (plebeius.eth)" Date: Thu, 30 Jan 2025 22:05:54 +0100 Subject: [PATCH] feat(settings modal): close with escape key --- src/components/settings-modal/settings-modal.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/components/settings-modal/settings-modal.tsx b/src/components/settings-modal/settings-modal.tsx index 01ff2a3b..881bcd09 100644 --- a/src/components/settings-modal/settings-modal.tsx +++ b/src/components/settings-modal/settings-modal.tsx @@ -21,6 +21,19 @@ const SettingsModal = () => { navigate(newPath); }; + useEffect(() => { + const handleEscape = (e: KeyboardEvent) => { + if (e.key === 'Escape') { + closeModal(); + } + }; + document.addEventListener('keydown', handleEscape); + + return () => { + document.removeEventListener('keydown', handleEscape); + }; + }, [closeModal]); + const [showInterfaceSettings, setShowInterfaceSettings] = useState(false); const [showAccountSettings, setShowAccountSettings] = useState(false); const [showAvatarSettings, setShowAvatarSettings] = useState(false);