Repository navigation
[SwipeableDrawer] Fix scrolling containers with overflow-x: hidden when anchor is top or bottom - #49826
[SwipeableDrawer] Fix scrolling containers with overflow-x: hidden when anchor is top or bottom#49826awingmawe wants to merge 2 commits into
Conversation
Deploy previewBundle size
PerformanceNo 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. |
0c793b4 to
474f97f
Compare
474f97f to
d98f4ae
Compare
ZeeshanTamboli
left a comment
There was a problem hiding this comment.
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.styleare 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 withposition: fixed; bottom: 0is 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.
| const visualViewport = containerWindow.visualViewport; | ||
| const viewportBottom = visualViewport | ||
| ? visualViewport.height + visualViewport.offsetTop | ||
| : containerWindow.innerHeight; | ||
|
|
||
| return viewportBottom - touches[0].clientY; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
oh, I missed this unnecessary fallback, you're right. thanks!
| const viewportOffset = | ||
| containerWindow.innerHeight - visualViewport.height - visualViewport.offsetTop; | ||
| const bottom = Math.max(0, Math.round(viewportOffset)); |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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.
| activePaper.style.bottom = bottom > 0 ? `${bottom}px` : ''; | ||
| activePaper.style.maxHeight = bottom > 0 ? `${maxHeight}px` : ''; |
There was a problem hiding this comment.
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.
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? |
…r with visualViewport (mui#49825)
…r top/bottom anchors
ef3a4bb to
6f86f43
Compare
Closes #49825
Summary
Fixes
getDomTreeShapesinpackages/mui-material/src/SwipeableDrawer/SwipeableDrawer.jsso vertical scroll containers insideanchor="top"oranchor="bottom"drawers are not skipped when they useoverflow-x: hidden.getDomTreeShapespreviously hardcodedstyle.getPropertyValue('overflow-x') === 'hidden'(inherited from horizontal-onlyreact-swipeable-views). PassinghorizontalSwipemakes it checkoverflow-xfor horizontal anchors (left/right) andoverflow-yfor vertical anchors (top/bottom), preventingSwipeableDrawerfrom hijacking vertical touch scrolling on containers styled withoverflow-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
should not ignore vertical scroll container with overflow-x hidden when anchor="bottom"inpackages/mui-material/src/SwipeableDrawer/SwipeableDrawer.test.js(it.skipIf(isJsdom())), verifyingtouchmoveon a child container withoverflowX: 'hidden', overflowY: 'auto'completes withdefaultPrevented: false.visualViewportchanges 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/materialin the StackBlitzBeforerepro'spackage.jsonto test live; CircleCItest_browser,test_unit,test_lint, andtest_e2epassed onef3a4bb8).