Skip to content

Commit

Permalink
Do not close non-closable dialog on escape press
Browse files Browse the repository at this point in the history
  • Loading branch information
Machy8 committed Jul 2, 2024
1 parent ba56445 commit efac627
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/signalizejs/src/modules/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit efac627

Please sign in to comment.