Skip to content

Commit fb5ef05

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 f8ba137 commit fb5ef05

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

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

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

160+
it(
161+
`should't do anything if the page isn't scrollable while zoomed out`,
162+
skipIOS(() => {
163+
if (platform.FIREFOX) {
164+
// style.zoom is only supported from Firefox 126
165+
return;
166+
}
167+
168+
forceScrollElement.style.display = 'none';
169+
document.body.style.zoom = '75%';
170+
overlayRef.attach(componentPortal);
171+
expect(document.body.scrollWidth).toBeGreaterThan(window.innerWidth);
172+
expect(documentElement.classList).not.toContain('cdk-global-scrollblock');
173+
overlayRef.detach();
174+
document.body.style.zoom = '100%';
175+
176+
document.documentElement.style.zoom = '75%';
177+
overlayRef.attach(componentPortal);
178+
expect(document.body.scrollWidth).toBeGreaterThan(window.innerWidth);
179+
expect(documentElement.classList).not.toContain('cdk-global-scrollblock');
180+
document.documentElement.style.zoom = '100%';
181+
}),
182+
);
183+
184+
it(
185+
`should add cdk-global-scrollblock while zoomed in`,
186+
skipIOS(() => {
187+
if (platform.FIREFOX) {
188+
// style.zoom is only supported from Firefox 126
189+
return;
190+
}
191+
192+
forceScrollElement.style.width = window.innerWidth - 20 + 'px';
193+
forceScrollElement.style.height = window.innerHeight - 20 + 'px';
194+
overlayRef.attach(componentPortal);
195+
expect(documentElement.classList).not.toContain('cdk-global-scrollblock');
196+
overlayRef.detach();
197+
198+
document.body.style.zoom = '200%';
199+
overlayRef.attach(componentPortal);
200+
expect(documentElement.classList).toContain('cdk-global-scrollblock');
201+
document.body.style.zoom = '100%';
202+
overlayRef.detach();
203+
204+
document.documentElement.style.zoom = '200%';
205+
overlayRef.attach(componentPortal);
206+
expect(documentElement.classList).toContain('cdk-global-scrollblock');
207+
document.documentElement.style.zoom = '100%';
208+
}),
209+
);
210+
160211
it('should keep the content width', () => {
161212
forceScrollElement.style.width = '100px';
162213

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)