Repository navigation
fix(scroll lock): keep Safari from panning the locked page for the on-screen keyboard - #727
Merged
Merged
Conversation
… the keyboard iOS pans the visual viewport down the layout to reveal a focused field once the on-screen keyboard opens, which moves fixed modals up with the page. Edge modals ended above the keyboard by the panned distance with their top outside of the screen. The keyboard store now tracks the pan, useVirtualKeyboard returns it as offset, and Modal moves it from its bottom inset to its top one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKGZMi1nf8CnLci2kLKjSy
…s it for the keyboard" This reverts commit a5b886f.
…-screen keyboard iOS pans the whole page to reveal a focused field even while the page scroll is locked with overflow, which moves the fixed content rendered above it, like modals, outside of the screen. While the page is locked on iOS, pressed fields are focused without letting Safari pan for them, the focused field is revealed inside its own scrollable container, and a page panned anyway is put back. Replaces following the pan with the modal position. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKGZMi1nf8CnLci2kLKjSy
size-limit report 📦
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces #726, which followed the pan with the modal position. That commit is reverted on this branch, so the diff against main is only the scroll lock change below.
Since #723, edge modals end above the on-screen keyboard. That layout is correct as long as the page stays where it is. But iOS Safari pans the whole page to reveal a focused field, even while the page scroll is locked with overflow. The pan moves fixed content up with the page, so a modal ended above the keyboard by the keyboard height with its top off screen.
A pan is the page scrolling behind an open overlay, so the fix is in the scroll lock. While the page scroll is locked on iOS (
preventKeyboardPaninpackages/utilities/src/scroll/keyboardPan.ts, called fromlockSafariScroll):mousedown(capture) over a field that opens the keyboard, the lock focuses the field itself withpreventScroll. For the synchronous focus call, the field is moved 2000px above the screen and hidden, then restored before anything is painted. Safari resolves the pan from the field's geometry at focus time, andpreventScrollalone doesn't stop it for fields inside transformed containers, which every modal is.caretPositionFromPoint.resize), the focused field, or the caret of an editable area, is scrolled into the visible part of its closest scrollable container. The page isn't moved.Left alone: a field that is already focused (the native tap moves its caret), buttons, links and selects inside an editable area,
contenteditable="false"islands, and inputs that don't open a keyboard (checkbox, readonly, disabled and so on).How it compares to other libraries
Drawer.VirtualKeyboardProvider): the focus trick is the same as itsfocusKeyboardInputWithoutPageScroll: off-screen transform pluspreventScrollfor the synchronous focus call. Its source notes that "iOS Safari can still scroll the page for transformed sheets even with preventScroll". It also puts a panned page back. It triggers ontouchendand re-dispatches the click; this PR triggers onmousedownand doesn't prevent anything.usePreventScroll): older versions, like the copy bundled in Vaul, used the same off-screen transform ontouchendandfocus, and scrolled the window back. The current version dropped the transform. It patchesHTMLElement.prototype.focusto always passpreventScroll, re-focuses the incoming field from theblurof the outgoing one, cancelstouchmoveoutside scrollable areas, and injectsoverscroll-behavior: contain. This PR does none of those four.Related Issue
Follow-up to #723: the Untap page modal ended far above the keyboard on iOS.
Screenshots / Recordings
Not tested on an iOS device yet. All of this only runs when
isIOS()is true.Notes for Reviewers
keyboardPan.test.ts(8 tests) covers: the focus call seeing the overridden geometry andpreventScroll, inline styles restored, caret placement, editable areas and the controls inside them, fields left to the browser, the page put back (and not while zoomed or without a focused field), the locked scroll position kept, the reveal after the keyboard opens, and release.lockSafari.test.tschecks the lock installs and removes the handling.touchmove. The backstop puts the page back instead.mousedownhandlers that check whether a field is focused will see it focused already.Generated by Claude Code