fix(busy): swallow the scrolling keys while a blocking operation runs

inert removes the controls from focus but not the document scroll: Space, PageUp/Down, Home/End and the arrows scroll without any focused element, so the page still moved under the overlay.
This commit is contained in:
r-zakarya
2026-08-01 19:12:36 +01:00
parent e07488e8b4
commit dca98dde9b
2 changed files with 14 additions and 0 deletions
+12
View File
@@ -7410,6 +7410,18 @@ async function init() {
// BEFORE any input-level handler that might call stopPropagation, and
// before the browser swallows the keystroke for things like clearing
// an active form-autocomplete popup on a focused field.
// `inert` takes the controls out of reach but does NOT stop the browser's
// own scrolling keys — Space, PageUp/Down, Home/End and the arrows scroll
// the document without needing a focused element. Swallow them while a
// blocking operation is running; everything else (Esc, shortcuts) is
// already handled by the guards on each feature.
document.addEventListener('keydown', e => {
if (!isBusy()) return;
const scrolls = [' ', 'Spacebar', 'PageUp', 'PageDown', 'Home', 'End',
'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'];
if (scrolls.indexOf(e.key) !== -1) e.preventDefault();
}, true);
document.addEventListener('keydown', e => {
if (e.key !== 'Escape') return;
if (!$('#slideover').classList.contains('is-open')) return;