Skip to content

fix(block-scroll-strategy): don't overwrite scrollBehavior #17604

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

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 6 additions & 3 deletions src/cdk/overlay/scroll/block-scroll-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import {ScrollStrategy} from './scroll-strategy';
import {ViewportRuler} from '@angular/cdk/scrolling';
import {coerceCssPixelValue} from '@angular/cdk/coercion';
import {supportsScrollBehavior} from '@angular/cdk/platform';

/**
* Extended `CSSStyleDeclaration` that includes `scrollBehavior` which isn't part of the
Expand Down Expand Up @@ -60,8 +61,8 @@ export class BlockScrollStrategy implements ScrollStrategy {
const body = this._document.body!;
const htmlStyle = html.style as ScrollBehaviorCSSStyleDeclaration;
const bodyStyle = body.style as ScrollBehaviorCSSStyleDeclaration;
const previousHtmlScrollBehavior = htmlStyle.scrollBehavior || '';
const previousBodyScrollBehavior = bodyStyle.scrollBehavior || '';
const previousHtmlScrollBehavior = htmlStyle.scrollBehavior;
const previousBodyScrollBehavior = bodyStyle.scrollBehavior;

this._isEnabled = false;

Expand All @@ -71,7 +72,9 @@ export class BlockScrollStrategy implements ScrollStrategy {

// Disable user-defined smooth scrolling temporarily while we restore the scroll position.
// See https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-behavior
htmlStyle.scrollBehavior = bodyStyle.scrollBehavior = 'auto';
if (supportsScrollBehavior()) {
htmlStyle.scrollBehavior = bodyStyle.scrollBehavior = 'auto';
}

window.scroll(this._previousScrollPosition.left, this._previousScrollPosition.top);

Expand Down