From 6852133b834c8cf8a0d62448aa9b5d152af1fd45 Mon Sep 17 00:00:00 2001 From: Mahdi Khashan Date: Sun, 5 May 2024 11:52:19 +0200 Subject: [PATCH] close drawer on `Escape` key press when it's open --- .../src/main/resources/static/js/main.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/boudicca.base/publisher-event-html/src/main/resources/static/js/main.js b/boudicca.base/publisher-event-html/src/main/resources/static/js/main.js index fed7ce1e..29394c22 100644 --- a/boudicca.base/publisher-event-html/src/main/resources/static/js/main.js +++ b/boudicca.base/publisher-event-html/src/main/resources/static/js/main.js @@ -52,6 +52,13 @@ document.addEventListener("DOMContentLoaded", () => { } }) + document.addEventListener("keydown", (event) => { + const drawerIsOpen = drawer.classList.contains("drawer-open") + if (event.key === "Escape" && drawerIsOpen) { + closeDrawer() + } + }) + const openDraw = () => { drawer.classList.add("drawer-open"); document.body.style.overflow = "hidden";