Base: Use native light dismiss for settings dialogs

Rather than rolling our own JavaScript to detect clicks outside of the
dialogs and close them we can set the closedby attribute to "any" which
will do the same thing.

This should also handle platform-specific user actions like pressing the
Escape key but this doesn't currently work so keep our JavaScript to
handle that and add a FIXME.
This commit is contained in:
James Raspass
2026-04-06 20:14:06 +01:00
committed by Tim Flynn
parent 48c3dda3fe
commit a629317840
Notes: github-actions[bot] 2026-04-08 01:28:43 +00:00

View File

@@ -574,7 +574,7 @@
</div>
</div>
<dialog id="languages-dialog">
<dialog id="languages-dialog" closedby="any">
<div class="dialog-header">
<h3 class="dialog-title">Languages</h3>
<button id="languages-close" class="close-button dialog-button">&times;</button>
@@ -591,7 +591,7 @@
</div>
</dialog>
<dialog id="search-dialog">
<dialog id="search-dialog" closedby="any">
<div class="dialog-header">
<h3 class="dialog-title">Search Settings</h3>
<button id="search-close" class="close-button dialog-button">&times;</button>
@@ -616,7 +616,7 @@
</div>
</dialog>
<dialog id="site-settings">
<dialog id="site-settings" closedby="any">
<div class="dialog-header">
<h3 id="site-settings-title" class="dialog-title"></h3>
<button id="site-settings-close" class="close-button dialog-button">&times;</button>
@@ -639,7 +639,7 @@
</div>
</dialog>
<dialog id="browsing-data-settings-dialog">
<dialog id="browsing-data-settings-dialog" closedby="any">
<div class="dialog-header">
<h3 class="dialog-title">Clear Browsing Data</h3>
<button id="browsing-data-settings-close" class="close-button dialog-button">&times;</button>
@@ -722,20 +722,8 @@
switchTab(hash);
}
// FIXME: Remove this once closedby="any" triggers for Esc key.
document.querySelectorAll("dialog").forEach(dialog => {
dialog.addEventListener("click", event => {
const rect = dialog.getBoundingClientRect();
if (
event.clientX < rect.left ||
event.clientX > rect.right ||
event.clientY < rect.top ||
event.clientY > rect.bottom
) {
dialog.close();
}
});
dialog.addEventListener("keydown", event => {
if (event.key === "Escape") {
dialog.close();