Skip to content

Commit dab2ca0

Browse files
committed
Escape key should dismiss prompt modal too
1 parent 746ad03 commit dab2ca0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

styles/all/template/webpush.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ function PhpbbWebpush() {
3333
/** @type {HTMLElement} Unsubscribe button */
3434
let unsubscribeButton;
3535

36+
/** @type {function} Escape key handler for popup */
37+
let popupEscapeHandler;
38+
3639
/**
3740
* Init function for phpBB Web Push
3841
* @type {array} options
@@ -185,6 +188,15 @@ function PhpbbWebpush() {
185188
promptDenied.set();
186189
}
187190
});
191+
192+
popupEscapeHandler = (event) => {
193+
if (event.key === 'Escape') {
194+
hidePopup(popup);
195+
promptDenied.set();
196+
}
197+
};
198+
199+
document.addEventListener('keydown', popupEscapeHandler);
188200
}
189201
}
190202

@@ -196,6 +208,8 @@ function PhpbbWebpush() {
196208
if (popup) {
197209
popup.style.display = 'none';
198210
}
211+
document.removeEventListener('keydown', popupEscapeHandler);
212+
popupEscapeHandler = null;
199213
}
200214

201215
/**

0 commit comments

Comments
 (0)