Skip to content

[SwipeableDrawer] Fix scrolling containers with overflow-x: hidden when anchor is top or bottom - #49826

Open
awingmawe wants to merge 2 commits into
mui:masterfrom
awingmawe:fix/swipeable-drawer-bottom-scroll-viewport
Open

awingmawe wants to merge 2 commits into
mui:masterfrom
awingmawe:fix/swipeable-drawer-bottom-scroll-viewport

Conversation

@awingmawe

@awingmawe awingmawe commented Nov 18, 2026 •

Copy link
Copy Markdown

Closes #49825

Summary

Fixes getDomTreeShapes in packages/mui-material/src/SwipeableDrawer/SwipeableDrawer.js so vertical scroll containers inside anchor="top" or anchor="bottom" drawers are not skipped when they use overflow-x: hidden.

getDomTreeShapes previously hardcoded style.getPropertyValue('overflow-x') === 'hidden' (inherited from horizontal-only react-swipeable-views). Passing horizontalSwipe makes it check overflow-x for horizontal anchors (left / right) and overflow-y for vertical anchors (top / bottom), preventing SwipeableDrawer from hijacking vertical touch scrolling on containers styled with overflow-x: hidden; overflow-y: auto.

 /**
  * @param {Element | null} element
  * @param {Element} rootNode
+ * @param {boolean} horizontalSwipe
  */
-function getDomTreeShapes(element, rootNode) {
+function getDomTreeShapes(element, rootNode, horizontalSwipe) {
   const domTreeShapes = [];
+  const overflowHiddenProperty = horizontalSwipe ? 'overflow-x' : 'overflow-y';

   while (element) {
     const style = ownerWindow(rootNode).getComputedStyle(element);

     if (
       style.getPropertyValue('position') === 'absolute' ||
-      style.getPropertyValue('overflow-x') === 'hidden'
+      style.getPropertyValue(overflowHiddenProperty) === 'hidden'
     ) {
       // noop
     }

Evidence

  • Added browser test should not ignore vertical scroll container with overflow-x hidden when anchor="bottom" in packages/mui-material/src/SwipeableDrawer/SwipeableDrawer.test.js (it.skipIf(isJsdom())), verifying touchmove on a child container with overflowX: 'hidden', overflowY: 'auto' completes with defaultPrevented: false.
  • Removed the earlier visualViewport changes and test per review feedback (keyboard/fixed-bottom tracking remains in [SwipeableDrawer] Can't scroll drawer content if anchor="bottom" and Virtual Keyboard is open #45730).

Reproductions:

Before: https://stackblitz.com/edit/github-9pb1tqkd?file=src%2FApp.tsx
After: Preview package published at https://pkg.pr.new/mui/material-ui/@mui/material@ef3a4bb8 (replace @mui/material in the StackBlitz Before repro's package.json to test live; CircleCI test_browser, test_unit, test_lint, and test_e2e passed on ef3a4bb8).

@code-infra-dashboard

code-infra-dashboard Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-49826--material-ui.netlify.app/
QR code for https://deploy-preview-49826--material-ui.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/material 🔺+23B(0.00%) 🔺+10B(+0.01%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Performance

No regressions in 32 benchmarks · precise to ±8.3% (±11.8% at worst) · ran 3m 17s · details


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

@awingmawe
awingmawe force-pushed the fix/swipeable-drawer-bottom-scroll-viewport branch 4 times, most recently from 0c793b4 to 474f97f Compare November 18, 2026 11:28
@zannager zannager added the component: SwipeableDrawer The React component. label Nov 20, 2026
@awingmawe
awingmawe force-pushed the fix/swipeable-drawer-bottom-scroll-viewport branch from 474f97f to d98f4ae Compare November 20, 2026 16:19
@ZeeshanTamboli ZeeshanTamboli changed the title [SwipeableDrawer] Fix vertical scroll detection with overflow-x: hidden and bottom touch Y with visualViewport [swipeable drawer] Fix vertical scroll detection with overflow-x: hidden and bottom touch Y with visualViewport Nov 27, 2026
@ZeeshanTamboli ZeeshanTamboli added the type: bug It doesn't behave as expected. label Nov 27, 2026

@ZeeshanTamboli ZeeshanTamboli left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for working on this! The getDomTreeShapes change fixes the scroll container bug from #49825. I checked it in Chromium: the new overflow-x: hidden test fails on master and passes with the change, and the existing tests still pass.

The visualViewport changes should come out of this PR, though:

  • They cause regressions, described in the inline comments. The main one: paper styles passed through slotProps.paper.style are cleared every time the drawer opens, even with no keyboard. Pinch-zoom also moves and shrinks the drawer as if the keyboard were open.
  • The keyboard covering the bottom of the page isn't specific to SwipeableDrawer. iOS Safari and Chrome Android show the keyboard on top of the page without resizing it, so every element with position: fixed; bottom: 0 is affected. That's tracked in #45730 and needs its own discussion.

Could you reduce the PR to the getDomTreeShapes fix and the first test (should not ignore vertical scroll container with overflow-x hidden when anchor="bottom")? The second test goes away with the effect. A title like [SwipeableDrawer] Fix scrolling containers with overflow-x: hidden when anchor is top or bottom would then match the change.

Comment on lines +47 to +52
const visualViewport = containerWindow.visualViewport;
const viewportBottom = visualViewport
? visualViewport.height + visualViewport.offsetTop
: containerWindow.innerHeight;

return viewportBottom - touches[0].clientY;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This measures from the bottom of the visual viewport, which only matches the paper's position after the new effect has moved the paper there. When the effect isn't running (for example while the drawer is closed and the page is pinch-zoomed), the paper and swipe area are still at the bottom of the layout viewport, so the swipe-area check and paperHit would use the wrong edge. Since this is only needed together with the effect, could you revert it too?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sure, it has been updated in ef3a4bb. You're right—I hadn't considered pinch zoom; thanks, @ZeeshanTamboli, this has given me some insight and prompted me to conduct further testing.

* @param {boolean} [horizontalSwipe]
*/
function getDomTreeShapes(element, rootNode) {
function getDomTreeShapes(element, rootNode, horizontalSwipe = true) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: the only caller always passes horizontalSwipe, so the default value isn't needed. The size-check change below isn't needed either: computeHasNativeHandler only reads the swipe axis, so the fix can be just the overflow-x/overflow-y line.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

oh, I missed this unnecessary fallback, you're right. thanks!

Comment on lines +632 to +634
const viewportOffset =
containerWindow.innerHeight - visualViewport.height - visualViewport.offsetTop;
const bottom = Math.max(0, Math.round(viewportOffset));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Pinch-zoom shrinks visualViewport.height the same way the keyboard does, and this doesn't check visualViewport.scale. With a mocked 2x zoom and no keyboard, the paper moved to bottom: 448px and shrank to maxHeight: 412px. This affects pinch-zoom on iOS and Android, and trackpad pinch-zoom on desktop.

const viewportOffset =
containerWindow.innerHeight - visualViewport.height - visualViewport.offsetTop;
const bottom = Math.max(0, Math.round(viewportOffset));
const maxHeight = Math.max(240, Math.floor(visualViewport.height * 0.92));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Because it's set inline, this maxHeight overrides any maxHeight set with sx or theme styleOverrides. The 240px minimum can also be taller than the visible area (for example in landscape with the keyboard open), which cuts off the top of the drawer.

Comment on lines +637 to +638
activePaper.style.bottom = bottom > 0 ? `${bottom}px` : '';
activePaper.style.maxHeight = bottom > 0 ? `${maxHeight}px` : '';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These lines clear bottom and maxHeight even when there's no keyboard (bottom === 0), and the cleanup clears them again. React doesn't re-apply inline styles that haven't changed, so styles passed through slotProps.paper.style are lost. With slotProps={{ paper: { style: { maxHeight: '123px', bottom: '56px' } } }}, both are empty after the drawer opens, with no keyboard involved. I checked this in Chromium; master keeps them.

@awingmawe awingmawe changed the title [swipeable drawer] Fix vertical scroll detection with overflow-x: hidden and bottom touch Y with visualViewport [SwipeableDrawer] Fix scrolling containers with overflow-x: hidden when anchor is top or bottom Nov 28, 2026
@awingmawe

awingmawe commented Nov 28, 2026 •

Copy link
Copy Markdown
Author

Thanks for working on this! The getDomTreeShapes change fixes the scroll container bug from #49825. I checked it in Chromium: the new overflow-x: hidden test fails on master and passes with the change, and the existing tests still pass.

The visualViewport changes should come out of this PR, though:

  • They cause regressions, described in the inline comments. The main one: paper styles passed through slotProps.paper.style are cleared every time the drawer opens, even with no keyboard. Pinch-zoom also moves and shrinks the drawer as if the keyboard were open.
  • The keyboard covering the bottom of the page isn't specific to SwipeableDrawer. iOS Safari and Chrome Android show the keyboard on top of the page without resizing it, so every element with position: fixed; bottom: 0 is affected. That's tracked in [SwipeableDrawer] Can't scroll drawer content if anchor="bottom" and Virtual Keyboard is open #45730 and needs its own discussion.

Could you reduce the PR to the getDomTreeShapes fix and the first test (should not ignore vertical scroll container with overflow-x hidden when anchor="bottom")? The second test goes away with the effect. A title like [SwipeableDrawer] Fix scrolling containers with overflow-x: hidden when anchor is top or bottom would then match the change.

Thanks for the thorough review and testing! I just reverted the changes for visualViewport and kept the changes to focus on getDomTreeShapes. About the visualViewport, if I want to contribute fixing the visualViewport, should I continue make a changes in this discussion #45730? or making new issues?

@awingmawe
awingmawe force-pushed the fix/swipeable-drawer-bottom-scroll-viewport branch from ef3a4bb to 6f86f43 Compare November 28, 2026 13:18

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

component: SwipeableDrawer The React component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[swipeable drawer] Can't scroll containers with overflow-x: hidden when anchor is top or bottom

3 participants