[Modal] Skip scrollbar compensation when the gutter is stable - #49079
Open
Janpot wants to merge 4 commits into
Open
[Modal] Skip scrollbar compensation when the gutter is stable#49079Janpot wants to merge 4 commits into
Janpot wants to merge 4 commits into
Conversation
The scroll lock hides the overflow of the scroll container, which removes the scrollbar and widens the viewport. It compensates by adding the scrollbar width as padding-right to the container and to .mui-fixed elements, but that compensation is wrong when the page reserves the scrollbar space with scrollbar-gutter: stable — the gutter survives overflow: hidden, so nothing moves and the padding shifts the content. Read the computed scrollbar-gutter of the scroll container and skip the compensation when it is stable. Reading the computed value doubles as a feature detection: unsupported browsers resolve it to an empty string and keep the existing behaviour. The docs opt in, which fixes the cookie banner jumping to the right when a Select opens. Also neutralise the margin-right that DocSearch puts on the body on open: it compensates for a scrollbar that never disappears here, shifting the page to the left.
Deploy previewBundle size
Check out the code infra dashboard for more information about this PR. |
Janpot
marked this pull request as ready for review
September 2, 2026 14:19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The docs set
html { overflow-y: scroll }. Opening a Select setsoverflow: hiddenon<html>, so the scrollbar vanishes and right-anchored fixed elements jump — most visibly the cookie banner.scrollbar-gutter: stablefixes that, but enabling it alone shifted the page the other way:isOverflowing()is still true while a gutter is reserved, so the scroll container got apadding-rightnothing cancelled out.ModalManagernow skips the compensation when the computed gutter is stable. Unsupported browsers resolve it to''and keep today's behaviour. Docs opt in.Separately, the search box shifted left because
@docsearch/reactsetsmargin-right: <scrollbar width>on the body to compensate for a scrollbar that never disappears here.Closes #40748 (was moved to base ui before)
try it out on https://deploy-preview-49079--material-ui.netlify.app/material-ui/react-select/