Skip to content

Keep the page behind a modal from scrolling on touch - #409

Merged
drudge merged 1 commit into
mainfrom
fix/modal-scroll-lock
Oct 8, 2026
Merged

drudge merged 1 commit into
mainfrom
fix/modal-scroll-lock

Conversation

@drudge

@drudge drudge commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Problem

On iOS Safari the page behind an open modal (e.g. the Insights finding drawer) still scrolls by touch. `html:has(dialog[open]) { overflow: hidden }` covers wheel/trackpad, but iOS ignores root overflow for touch scrolling. A drag on the drawer header or backdrop scrolls the document, the toolbar collapses, and the drawer slides off with the page.

Fix

  • app.js: while a `:modal` dialog is open, a non-passive `touchmove` guard calls `preventDefault` unless the touch is inside the modal on an element that can scroll along the gesture's axis. Text fields, selects, and contenteditable keep their drags.
  • app.css: `dialog[open] * { overscroll-behavior: contain }`, so scrollers in a modal (e.g. `.query-detail-body`) don't chain to the page when they hit an edge.

I chose this over pinning `` with `position: fixed` because that breaks `position: sticky` (`.mobile-header`, the replica banner) behind centered modals and has to restore the scroll offset afterward.

Tests

  • New `TestBrowserModalScrollLock` (`-tags browser`, `scripts/browser/modal-scroll-lock.cjs`) sends real CDP touches on a 390×844 touch viewport. It checks that backdrop drags and drags on a modal part that can't scroll are refused, and that a scroller inside the modal still scrolls and contains overscroll. It fails without the app.js change.
  • `TestBrowserNavSwipe` still passes. `mage verify` is green.

No visual change, so there are no before and after screenshots.

iOS Safari ignores overflow: hidden on the root for touch scrolling, so a
drag on an open drawer's backdrop or header scrolled the page behind it,
collapsed the toolbar, and slid the drawer off screen. Refuse touch moves
while a modal is open unless they land in a scroller inside it that can move
along the gesture, and contain overscroll in those scrollers so they don't
chain to the page.
@drudge
drudge merged commit ef2caab into main Oct 8, 2026
4 checks passed
@drudge
drudge deleted the fix/modal-scroll-lock branch October 8, 2026 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant