Prompts can be closed by keyboard: Enter emulates the default button click, Escape the cancel action.

This commit is contained in:
hackademix 2022-03-14 21:29:10 +01:00
parent 5aeb7f3c75
commit 2b0c9e87bf
1 changed files with 13 additions and 0 deletions

View File

@ -115,6 +115,19 @@
b.addEventListener("click", buttonClicked);
}
addEventListener("keydown", e => {
if (e.ctrlKey || e.metaKey || e.shiftKey) return;
switch(e.code) {
case "Escape":
window.close();
return;
case "Enter":
let defButton = document.querySelector("#buttons button[type=submit]");
if (defButton) defButton.click();
return;
}
});
let resize = async e => {
if (!("windows" in browser)) {
// tabbed (mobile?) - ensure buttons are visible