Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid moving content when blocking scrolling #3369

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/elements/core/dom/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export function pageScrollDisabled(): boolean {
*/
export class SbbScrollHandler {
private _height!: string;
private _position!: string;
private _overflow!: string;
private _marginInlineEnd!: string;

Expand All @@ -18,13 +19,15 @@ export class SbbScrollHandler {

// Save any pre-existing styles to reapply them to the body when enabling the scroll again.
this._height = document.body.style.height;
this._position = document.body.style.position;
this._overflow = document.body.style.overflow;
this._marginInlineEnd = document.body.style.marginInlineEnd;

const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;

document.body.style.overflow = 'hidden';
document.body.style.height = '100%';
document.body.style.height = '100dvh';
document.body.style.position = 'relative';
document.body.style.marginInlineEnd = `${scrollbarWidth}px`;
document.body.style.setProperty('--sbb-scrollbar-width', `${scrollbarWidth}px`);

Expand All @@ -38,6 +41,7 @@ export class SbbScrollHandler {

// Revert body inline styles.
document.body.style.height = this._height || '';
document.body.style.position = this._position || '';
document.body.style.overflow = this._overflow || '';
document.body.style.marginInlineEnd = this._marginInlineEnd || '';
document.body.style.setProperty('--sbb-scrollbar-width', '0');
Expand Down
Loading