From efac62729f9860c6409207835d7cd60d2c20e554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr?= <8machy@seznam.cz> Date: Tue, 2 Jul 2024 10:24:05 +0200 Subject: [PATCH] Do not close non-closable dialog on escape press --- packages/signalizejs/src/modules/dialog.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/signalizejs/src/modules/dialog.js b/packages/signalizejs/src/modules/dialog.js index b4e44fe..6d586ee 100755 --- a/packages/signalizejs/src/modules/dialog.js +++ b/packages/signalizejs/src/modules/dialog.js @@ -45,6 +45,9 @@ export default async ({ resolve, root, params }) => { if (dialog.hasAttribute(dialogModelessAttribute)) { modelessly = dialog.getAttribute(dialogModelessAttribute) === 'true'; } + + dialog.setAttribute(dialogClosableAttribute, String(closable)); + modelessly ? dialog.show() : dialog.showModal(); const dialogId = dialog.getAttribute(dialogAttribute); if (dialogId) { @@ -69,7 +72,9 @@ export default async ({ resolve, root, params }) => { dialog.close(); if (dialog.getAttribute(dialogAttribute) === window.location.hash.substring(1)) { - window.history.replaceState(null, '', window.location.href.substring(0, window.location.href.indexOf('#'))); + window.history.replaceState( + null, '', window.location.href.substring(0, window.location.href.indexOf('#')) + ); } off('click', dialog, closeOnBackDropClickListener); @@ -113,6 +118,14 @@ export default async ({ resolve, root, params }) => { } }); + on('keydown', (event) => { + if (event.key.toLowerCase() === 'escape' + && document.querySelector(`dialog[open][${dialogClosableAttribute}="false"]`) + ) { + event.preventDefault(); + } + }); + on('dom:ready', () => { on('locationchange', window, openDialogByUrlHash); openDialogByUrlHash();