Skip to content

[Modal] Skip scrollbar compensation when the gutter is stable - #49079

Open
Janpot wants to merge 4 commits into
mui:masterfrom
Janpot:scrollbar-gutter-scroll-lock
Open

[Modal] Skip scrollbar compensation when the gutter is stable#49079
Janpot wants to merge 4 commits into
mui:masterfrom
Janpot:scrollbar-gutter-scroll-lock

Conversation

@Janpot

@Janpot Janpot commented Sep 2, 2026

Copy link
Copy Markdown
Member

The docs set html { overflow-y: scroll }. Opening a Select sets overflow: hidden on <html>, so the scrollbar vanishes and right-anchored fixed elements jump — most visibly the cookie banner.

scrollbar-gutter: stable fixes 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 a padding-right nothing cancelled out. ModalManager now 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/react sets margin-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/

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.
@Janpot Janpot added type: regression A bug, but worse, it used to behave as expected. docs Improvements or additions to the documentation. scope: modal Changes related to the modal. labels Sep 2, 2026
@code-infra-dashboard

code-infra-dashboard Bot commented Sep 2, 2026

Copy link
Copy Markdown

Deploy preview

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

Bundle size

Bundle Parsed size Gzip size
@mui/material 🔺+198B(+0.04%) 🔺+56B(+0.04%)
@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


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

@Janpot
Janpot requested a review from a team September 2, 2026 14:19
@Janpot
Janpot marked this pull request as ready for review September 2, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to the documentation. scope: modal Changes related to the modal. type: regression A bug, but worse, it used to behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant