Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.6k
Eliminate scroll-lock layout shift using JavaScript-based dynamic padding#12154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:dev
Are you sure you want to change the base?
Conversation
Co-authored-by: danielchalmers <7112040+danielchalmers@users.noreply.github.com>
…n clarificationCo-authored-by: danielchalmers <7112040+danielchalmers@users.noreply.github.com>
Co-authored-by: danielchalmers <7112040+danielchalmers@users.noreply.github.com>
danielchalmers commentedNov 24, 2025
@copilot Now it no longer hides the scrollbar when |
…ervedCo-authored-by: danielchalmers <7112040+danielchalmers@users.noreply.github.com>
Fixed in commit6fbaaa8. The scrollbar now properly disappears when scroll-locked is applied while the gutter space remains reserved to prevent layout shifts. The solution uses Screenshots: |
danielchalmers commentedNov 24, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Before (Edge v142) Recording.2025-11-23.193146.mp4After Recording.2025-11-23.193306.mp4Also tested on Firefox but no video. Haven't tested on older browser for backwards compatibility yet. |
versile2 left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@danielchalmers I do not like this solution. Instead of modifying css I would argue change the CSS to 0 padding and leave it alone. scroll-locked is ONLY used in one place. Replace it with a javascript solution (this is being added by javascript anyways). While I haven't tried it yet my understanding is you can write a javascript solution that will work seamlessly.
The reason I don't like this solution:
There isalways a blank strip on the side. On pages with no scroll it still reserves the space. When it shouldn't. Those look even weirder when you add scroll-locked and they suddenly have a blank strip where there was nothingness before. On pages with scroll it's not the worst but still doesn't look great. I could deal with that if it only added it in those scenarios where a scrollbar already exists, not sure css can tell though.
If you are fine with the blank strip always and the loss of the right side of every screen without a scrollbar this solution works. But I don't think it's okay. First two screenshots are before/after with a scrollbar second two is without scroll locked what it looks like before and after this PR when no scrollbar exists.




danielchalmers commentedNov 25, 2025
Really appreciate that feedback - will keep this on hold |
versile2 commentedNov 25, 2025
ask copilot to modify the javascript to achieve scroll lock where it doesn't shift the layout instead of pure css? It's only done in mudoverlay.razor.cs I believe. We could calculate the padding and set it manually in javascript. |
danielchalmers commentedDec 5, 2025
@copilot do this and respect the other feedback posted |
…alculation- Revert CSS-only scrollbar-gutter approach- Calculate actual scrollbar width dynamically in JavaScript- Apply padding-right as inline styles to body, appbar, and scroll-to-top elements- Store and restore original padding values to prevent conflicts- Remove hard-coded padding values from CSSCo-authored-by: danielchalmers <7112040+danielchalmers@users.noreply.github.com>
CopilotAI commentedDec 5, 2025 • edited by danielchalmers
Loading Uh oh!
There was an error while loading.Please reload this page.
edited by danielchalmers
Uh oh!
There was an error while loading.Please reload this page.
Implemented JavaScript-based scroll lock with dynamic scrollbar width calculation in commit186f1b0. The solution now:
|
…ll lock logicCo-authored-by: danielchalmers <7112040+danielchalmers@users.noreply.github.com>
…ntainabilityCo-authored-by: danielchalmers <7112040+danielchalmers@users.noreply.github.com>
Co-authored-by: danielchalmers <7112040+danielchalmers@users.noreply.github.com>
Co-authored-by: danielchalmers <7112040+danielchalmers@users.noreply.github.com>


Uh oh!
There was an error while loading.Please reload this page.
When MudBlazor locks scrolling (e.g., opening dialogs/drawers), layout shifts occur because the scrollbar disappears and the viewport width changes. This is particularly visible in the AppBar and causes content to jump horizontally.
Changes
JavaScript (
mudScrollManager.js)lockScroll()to dynamically calculate actual scrollbar width:window.innerWidth - document.documentElement.clientWidthbodyelement (preserving original padding).mud-appbarelements.mud-scroll-to-topelementsdata-original-padding-rightattributes before modificationunlockScroll()to restore original padding values for all elements_adjustPadding()and_restorePadding()for better code organization and performanceCSS (
_scroll.scss)overflow: hiddenin.scroll-lockedclassC# (
MudOverlay.razor.cs)ScrollManager.LockScrollAsync()andUnlockScrollAsync()methodsBenefits
How It Works
scrollBarWidth = window.innerWidth - document.documentElement.clientWidthgetComputedStyle()(returns pixels like "16px")Screenshots
Before Locking - No padding applied:

After Locking - Padding applied based on actual scrollbar width, no layout shift:

Testing
Checklist:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn moreCopilot coding agent tips in the docs.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn moreCopilot coding agent tips in the docs.