Skip to content

[drawer] Fix scroll handling when focus moves while the virtual keyboard is open - #5179

Merged
atomiks merged 7 commits into
mui:masterfrom
atomiks:claude/goofy-khorana-2fb324
Jul 19, 2026
Merged

atomiks merged 7 commits into
mui:masterfrom
atomiks:claude/goofy-khorana-2fb324

Conversation

@atomiks

@atomiks atomiks commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Steps (bug A):

  1. Virtual keyboard aware demo
  2. Tap an input on iOS
  3. Press arrow navigation keys to go between inputs (up/down)
  4. Should not use native handling

Steps (bug B):

  1. Virtual keyboard aware demo
  2. Tap the footer input on iOS
  3. Scroll the drawer container down to reach textarea
  4. Tap textarea
  5. Should correctly scroll it into view

With the keyboard already open, moving focus without a fresh tap broke the drawer's scroll containment:

  • The iOS keyboard's previous/next arrows move focus natively (no touch events, no preventScroll), so WebKit's reveal scroll panned the page and pushed the drawer offscreen.
  • Tapping a field in the scrollable body while a pinned footer field held focus didn't scroll it into view — no viewport events follow, and the single alignment pass measured layout still reacting to the focus change.

Fixes in DrawerVirtualKeyboardProvider:

  • Preempt the native reveal in focusout: briefly present the incoming field as already visible above the keyboard so WebKit has nothing to reveal, restoring in focusin.
  • Commit the centering scroll only once its destination stops moving between checks, so it never chases mid-transition layout.
  • Re-run alignment on a short interval after keyboard-open focus changes, re-issuing only scrolls that stalled (WebKit cancels in-flight smooth scrolls when its reveal resolves) — never restarting one in progress.
  • Pin the page scroll for modal drawers as a recovery net.

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.

@atomiks atomiks added component: drawer Changes related to the drawer component. type: bug It doesn't behave as expected. labels Jul 7, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@5179
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@5179
    

commit: 03012ab

@code-infra-dashboard

code-infra-dashboard Bot commented Jul 7, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+914B(+0.20%) 🔺+355B(+0.24%)

Details of bundle changes

Performance

Total duration: 1,605.63 ms +85.61 ms(+5.6%) | Renders: 78 (+0) | Paint: 2,530.31 ms +135.34 ms(+5.7%)

Test Duration Renders
Menu mount (300 instances) 189.52 ms 🔺+39.59 ms(+26.4%) 2 (+0)
Select open (500 options) 58.46 ms 🔺+13.42 ms(+29.8%) 14 (+0)
Popover mount (300 instances) 74.51 ms ▼-23.45 ms(-23.9%) 1 (+0)
Scroll Area mount (300 instances) 115.75 ms +10.82 ms(+10.3%) 3 (+0)

11 tests within noise — details

Metric alarms

Test Metric Change
Menu mount (300 instances) bench:paint 🔺 +56.86 ms
Select open (500 options) bench:paint 🔺 +30.15 ms
Select open (500 options) bench:paint#select-open 🔺 +30.15 ms
Scroll Area mount (300 instances) bench:paint 🔺 +23.63 ms

Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Jul 7, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 03012ab
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a5d4816dba5980008899e6d
😎 Deploy Preview https://deploy-preview-5179--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@aarongarciah

Copy link
Copy Markdown
Member

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

@atomiks

atomiks commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@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.

@atomiks
atomiks force-pushed the claude/goofy-khorana-2fb324 branch from 3686b4e to c143abc Compare July 14, 2026 09:21
@atomiks

atomiks commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

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.

@atomiks
atomiks marked this pull request as ready for review July 14, 2026 13:23
@atomiks
atomiks requested a review from Copilot July 17, 2026 08:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@atomiks
atomiks force-pushed the claude/goofy-khorana-2fb324 branch from 1a8baf3 to 03012ab Compare July 19, 2026 21:56
@atomiks
atomiks requested a review from Copilot July 19, 2026 21:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@atomiks
atomiks merged commit 5943dec into mui:master Jul 19, 2026
6 checks passed
@atomiks
atomiks deleted the claude/goofy-khorana-2fb324 branch July 19, 2026 22:08
legowhales added a commit to legowhales/svelte-base-drawer that referenced this pull request Aug 13, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: drawer Changes related to the drawer component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants