Skip to content

Commit 8545abc

Browse files
fix(cdk/overlay): scroll was blocked when zoomed out even if scrolling wasn't an option
Fixes that an unnecessary disabled scroll bar was added when zoomed out during opening dialogs. Fixes angular#25054.
1 parent 459cfb9 commit 8545abc

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

Diff for: src/cdk/overlay/scroll/block-scroll-strategy.spec.ts

+41
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,47 @@ describe('BlockScrollStrategy', () => {
157157
}),
158158
);
159159

160+
it(
161+
`should't do anything if the page isn't scrollable while zoomed out`,
162+
skipIOS(() => {
163+
forceScrollElement.style.display = 'none';
164+
document.body.style.zoom = '75%';
165+
overlayRef.attach(componentPortal);
166+
expect(document.body.scrollWidth).toBeGreaterThan(window.innerWidth);
167+
expect(documentElement.classList).not.toContain('cdk-global-scrollblock');
168+
overlayRef.detach();
169+
document.body.style.zoom = '100%';
170+
171+
document.documentElement.style.zoom = '75%';
172+
overlayRef.attach(componentPortal);
173+
expect(document.body.scrollWidth).toBeGreaterThan(window.innerWidth);
174+
expect(documentElement.classList).not.toContain('cdk-global-scrollblock');
175+
document.documentElement.style.zoom = '100%';
176+
}),
177+
);
178+
179+
it(
180+
`should add cdk-global-scrollblock while zoomed in`,
181+
skipIOS(() => {
182+
forceScrollElement.style.width = window.innerWidth - 20 + 'px';
183+
forceScrollElement.style.height = window.innerHeight - 20 + 'px';
184+
overlayRef.attach(componentPortal);
185+
expect(documentElement.classList).not.toContain('cdk-global-scrollblock');
186+
overlayRef.detach();
187+
188+
document.body.style.zoom = '200%';
189+
overlayRef.attach(componentPortal);
190+
expect(documentElement.classList).toContain('cdk-global-scrollblock');
191+
document.body.style.zoom = '100%';
192+
overlayRef.detach();
193+
194+
document.documentElement.style.zoom = '200%';
195+
overlayRef.attach(componentPortal);
196+
expect(documentElement.classList).toContain('cdk-global-scrollblock');
197+
document.documentElement.style.zoom = '100%';
198+
}),
199+
);
200+
160201
it('should keep the content width', () => {
161202
forceScrollElement.style.width = '100px';
162203

Diff for: src/cdk/overlay/scroll/block-scroll-strategy.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ export class BlockScrollStrategy implements ScrollStrategy {
9696
return false;
9797
}
9898

99-
const body = this._document.body;
99+
const rootElement = this._document.documentElement;
100100
const viewport = this._viewportRuler.getViewportSize();
101-
return body.scrollHeight > viewport.height || body.scrollWidth > viewport.width;
101+
return rootElement.scrollHeight > viewport.height || rootElement.scrollWidth > viewport.width;
102102
}
103103
}

0 commit comments

Comments
 (0)