Skip to content

Commit f11d46e

Browse files
crisbetojelbourn
authored andcommitted
fix(block-scroll-strategy): collapsing root node when enabled (#4638)
* Prevents the `html` tag from collapsing when the `BlockScrollStrategy` is enabled. * Fixes the scroll strategy not being disabled properly in tests.
1 parent 96549e8 commit f11d46e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/lib/core/overlay/_overlay.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@
7070
.cdk-global-scrollblock {
7171
position: fixed;
7272

73-
// Necessary for iOS not to expand past the viewport.
74-
max-width: 100vw;
73+
// Necessary for the content not to lose its width. Note that we're using 100%, instead of
74+
// 100vw, because 100vw includes the width plus the scrollbar, whereas 100% is the width
75+
// that the element had before we made it `fixed`.
76+
width: 100%;
7577

7678
// Note: this will always add a scrollbar to whatever element it is on, which can
7779
// potentially result in double scrollbars. It shouldn't be an issue, because we won't

src/lib/core/overlay/scroll/block-scroll-strategy.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ describe('BlockScrollStrategy', () => {
2323
}));
2424

2525
afterEach(() => {
26+
strategy.disable();
2627
document.body.removeChild(forceScrollElement);
2728
setScrollPosition(0, 0);
2829
});
@@ -110,6 +111,16 @@ describe('BlockScrollStrategy', () => {
110111
}));
111112

112113

114+
it('should keep the content width', () => {
115+
forceScrollElement.style.width = '100px';
116+
117+
const previousContentWidth = document.documentElement.getBoundingClientRect().width;
118+
119+
strategy.enable();
120+
121+
expect(document.documentElement.getBoundingClientRect().width).toBe(previousContentWidth);
122+
});
123+
113124
/**
114125
* Skips the specified test, if it is being executed on iOS. This is necessary, because
115126
* programmatic scrolling inside the Karma iframe doesn't work on iOS, which renders these

0 commit comments

Comments
 (0)