From 36105622eb659b4e00b6544d0f4312715a9e1169 Mon Sep 17 00:00:00 2001 From: Laurence Chen Date: Thu, 12 Sep 2024 17:06:25 +0800 Subject: [PATCH] let close dialog button handle the ESC key --- src/co/gaiwan/compass/html/components.clj | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/co/gaiwan/compass/html/components.clj b/src/co/gaiwan/compass/html/components.clj index 6912d71..0113e89 100644 --- a/src/co/gaiwan/compass/html/components.clj +++ b/src/co/gaiwan/compass/html/components.clj @@ -17,7 +17,12 @@ :hx-push-url (str (url-for :sessions/index)) :hx-target "body" :hx-swap "outerHTML"} - [graphics/cross]])) + [graphics/cross] + [:script + "document.addEventListener('keydown', function(event) { + if (event.key === 'Escape') { // check if ESC is pressed + document.getElementById('close-dialog').click(); // click the button + }});"]])) (o/defstyled toggle-button :label "Toggle implemented as a checkbox (can also be used as a radio button)."