Repository navigation
[drawer] Fix scroll handling when focus moves while the virtual keyboard is open - #5179
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,605.63 ms +85.61 ms(+5.6%) | Renders: 78 (+0) | Paint: 2,530.31 ms +135.34 ms(+5.7%)
11 tests within noise — details Metric alarms
Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Very nice. Tested on Safari 26.5 and it seems to work fine. I wonder if it'd be desirable or if it's possible to avoid the animated scroll when focusing the textarea in the video below? ScreenRecording_07-08-2026.11-38-14_1.MP4 |
|
@aarongarciah yeah I thought that looked kinda bad but it at least fixed the previous broken behavior. If there's a way to detect this particular edge case and disable scroll animations, I will apply it. |
3686b4e to
c143abc
Compare
|
Wasn't able to get that working smoothly. It's not severe and the current fix is better than before, so deferring to an issue or community fix. |
There was a problem hiding this comment.
Pull request overview
Improves Base UI’s Drawer virtual-keyboard handling to prevent WebKit’s native focus-reveal scrolling from breaking scroll containment when the iOS software keyboard is already open, and to ensure focused fields reliably scroll into view across focus transitions.
Changes:
- Preempt WebKit native reveal on keyboard-driven focus moves by temporarily overriding incoming field geometry during
focusout→focusin. - Make alignment scrolling more robust by waiting for the destination to settle and re-running alignment on a short interval after keyboard-open focus changes.
- Add extensive Chromium (non-JSDOM) regression tests covering native focus moves, stalled smooth scroll recovery, and modal page-scroll pinning.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/react/src/drawer/virtual-keyboard-provider/DrawerVirtualKeyboardProvider.tsx | Adds focus-reveal preemption, destination-settle logic, delayed realign passes, and modal page-scroll pinning while keyboard is open. |
| packages/react/src/drawer/virtual-keyboard-provider/DrawerVirtualKeyboardProvider.test.tsx | Adds browser-mode tests validating the new focus/scroll behavior and recovery mechanisms. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
1a8baf3 to
03012ab
Compare
Ports the six applicable Drawer fixes from the base-ui v1.7.0 release: - mui/base-ui#5105: reliable swipe-to-open — first-move re-anchoring is now gated on trackDrag (the SwipeArea passes trackDrag: false, so a flick whose whole travel lands in the first move still registers), and sawPrimaryButtonsOnMove initializes from the event type. - mui/base-ui#5308: drag styles are only rewritten when the offset actually changed, fixing the snap point jump when the pointer is pinned at a screen edge. The swipeThreshold function is snapshotted at gesture start. - mui/base-ui#5257: cross-axis touch arbitration rewritten (shouldYieldTouchMove) — 6px slop / 2px bias, one-shot attribution per gesture, non-cancelable moves yield to native scroll, and no preventDefault until an axis passes the slop (iOS kills native scrolling for the whole gesture otherwise). - mui/base-ui#5360: elementFromPoint resolves through getRootNode() so swipe gestures work inside shadow DOM. - mui/base-ui#5112: the popup no longer flashes fully open for a frame during a swipe-area open — resetAfterOpen skips the movement-var reset while the SwipeArea drives the gesture (swipeAreaActive), and the SwipeArea re-asserts its styles when the popup (re)mounts. - mui/base-ui#5179: virtual keyboard scroll handling rework for focus moves while the keyboard is open — interval realign passes, preemptive focus geometry override to neutralize WebKit's reveal scroll, window scroll pinning, programmatic-focus flag, settle-watching scroll bookkeeping. The SwipeArea outside-press guard is now deterministic (capture-phase pointerdown/click listeners + isVirtualClick) instead of a 300ms timer. Not ported (React-only): mui/base-ui#5109, Drawer.Handle/createHandle detached triggers, bundle-size refactors. Co-Authored-By: Claude Fable 5 <[email protected]>
Steps (bug A):
Steps (bug B):
With the keyboard already open, moving focus without a fresh tap broke the drawer's scroll containment:
preventScroll), so WebKit's reveal scroll panned the page and pushed the drawer offscreen.Fixes in
DrawerVirtualKeyboardProvider:focusout: briefly present the incoming field as already visible above the keyboard so WebKit has nothing to reveal, restoring infocusin.Verified on a physical iPhone (taps, arrows both directions, footer→body transitions, keyboard open/close); each mechanism has Chromium tests with a mocked visual viewport.