Skip to content

fix(reshaped, scroll lock): hand the iOS keyboard pan over to the focused field's container on pages the user can't scroll - #730

Open
blvdmitry wants to merge 2 commits into
mainfrom
claude/zealous-ptolemy-y4bqky
Open

blvdmitry wants to merge 2 commits into
mainfrom
claude/zealous-ptolemy-y4bqky

Conversation

@blvdmitry

@blvdmitry blvdmitry commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On iOS, when a field is focused near the end of a scroll container that can't scroll it above the keyboard, Safari pans the whole page instead. On a page the user can't scroll, nothing can pan it back while the keyboard is open, so the top of the page, or of an open modal, stays off screen. A page can't be scrolled in two cases:

This PR handles both automatically. It doesn't take over anything Safari does. It waits for Safari to finish, then moves the pan into the focused field's scroll container (packages/utilities/src/scroll/keyboardPan.ts):

  • When it runs: the page's resting position is tracked from its scroll events. It's frozen while a keyboard field is focused on a page the user can't scroll, because Safari can start panning before the viewport resize for the keyboard arrives. 200ms after the last page scroll, visual viewport scroll, focusin, touch end or keyboard change, if the keyboard is open and the page has moved from its resting position, the handoff runs.
  • What it does: the field's closest scroll container is scrolled by the pan, and the page is scrolled back to its resting position in the same frame. The field stays where Safari revealed it, and the rest of the page or modal comes back on screen.
  • Extra room: if the container can't scroll that far, the missing amount is added as inline padding-bottom while the keyboard is open. If the container grows with the padding instead of gaining room, the padding is dropped again.
  • Left alone: pages the user can scroll (they can scroll the pan back themselves), a finger on the screen, a pinch-zoomed page, and fields that don't open the keyboard.
  • Who starts it: the Reshaped provider on iOS (handOverIOSKeyboardPan, exported from @reshaped/utilities/internal), and lockSafariScroll for anyone using lockScroll without the provider. Both share a single counted instance, which stops when the last one releases it.

What's different from the attempts that were rolled back

#723 / #727 (rolled back in #729) This PR
Focus Focused pressed fields itself on mousedown, with an off-screen geometry override, and placed the caret Left to Safari
Panned page Scrolled back on every scroll event, including while Safari was still panning Moved into the container once the page has held still for 200ms
Modal geometry Edge modals ended above the keyboard, so with Safari's pan on top they ended up too high (gap, cut-off top) Unchanged; only padding inside the scroll container
Reveal Its own reveal pass scrolled the field into view Left to Safari
Scope Only under the scroll lock Any page the user can't scroll

Compared with Base UI

  • Default scroll lock: useScrollLock (Dialog, Drawer) on iOS only sets overflow, the same as Reshaped since fix(scroll lock, modal): leave revealing the focused field above the iOS keyboard to Safari #729. Its comment says the iOS keyboard behaviour "must be researched extensively" first. So a Base UI Dialog has the same problem.
  • Drawer: the keyboard handling is the opt-in Drawer.VirtualKeyboardProvider, for bottom sheets with form fields. It takes over taps on touchend, focuses with the same off-screen transform and preventScroll trick as fix(scroll lock): keep Safari from panning the locked page for the on-screen keyboard #727, and preempts the keyboard's previous/next field arrows on focusout. It pins the window scroll, adds bottom padding to the drawer's scroll body, and re-aligns over several frames and timed passes.
  • App-shell pages: Base UI does nothing outside an open Drawer with that provider.
  • This PR: borrows the padding idea only. It doesn't take over focus, pin the window or run an alignment loop, which are the parts that raced Safari here before.

Related Issue

Untap: with the page or a modal scrolled down and a field focused, the top can't be scrolled back to while the keyboard is open. Untap's own fix for its page is reshaped-ui/untap#202. Once this ships in a canary, that hook isn't needed.

Screenshots / Recordings

None. This only shows on an iOS device with the on-screen keyboard.

Notes for Reviewers

  • Not checked on an iPhone. This assumes Safari reports the pan in window.scrollY and that window.scrollTo moves it back, which the removed keyboardPan and Base UI's provider both rely on. Worth trying:

    • a bottom modal with a long form scrolled to its end;
    • an end modal;
    • an app-shell page (body { overflow: hidden }, content scrolling in a container) scrolled to its end;
    • a short center modal with a field near its bottom;
    • moving between fields with the keyboard's previous/next arrows.
  • The one visible change: Safari pans as before, then about 200ms after it stops, the frame (modal or page header) slides back into place while the focused field stays put.

  • Not covered: a short center modal whose content fits has no scroll container to hand the pan to, so it stays the way it is today.

  • The provider now starts a global listener set on iOS: window and visual viewport scroll, focusin, and touch start/end/cancel, all passive. Nothing runs on other platforms.

  • Tests: keyboardPan.test.ts (8 tests):

    • handing over with padding for the shortfall, removed when the keyboard closes;
    • back to a resting position that isn't 0;
    • a page the user can scroll left alone;
    • waiting for a touch to end;
    • a container that grows with padding;
    • no handoff without the keyboard;
    • the shared instance running until everything releases it.

    The provider's iOS check isn't covered, because the tests run in desktop Chromium. Also passing: utilities src/scroll and src/viewport; browser tests for Reshaped, Modal, Overlay and the hooks; tsc for both packages; lint and format.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TKGZMkda2DXoWdE6gq1RR8

…e to the focused field's container

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKGZMkda2DXoWdE6gq1RR8
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
Library / JS 54.5 KB (+1.01% 🔺) 1.1 s (+1.01% 🔺) 0 ms (+100% 🔺) 1.1 s
Library / CSS 24.83 KB (0%) 497 ms (0%) 0 ms (+100% 🔺) 497 ms
Theming / JS 7.8 KB (0%) 156 ms (0%) 186 ms (+109.01% 🔺) 342 ms
Theming with a default theme definition / JS 8.68 KB (0%) 174 ms (0%) 127 ms (-20.23% 🔽) 301 ms

…he user can't scroll, with or without a modal

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKGZMkda2DXoWdE6gq1RR8
@blvdmitry blvdmitry changed the title fix(scroll lock): hand a keyboard pan Safari leaves on the locked page to the focused field's container fix(reshaped, scroll lock): hand the iOS keyboard pan over to the focused field's container on pages the user can't scroll Nov 24, 2026

This branch has not been deployed

No deployments
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.

2 participants