Skip to content

Commit 96549e8

Browse files
crisbetojelbourn
authored andcommitted
fix(overlay): overlays potentially being rendered behind browser UI (#4664)
Reverts back from using viewport units to size up the overlay container. Using viewport units can cause some overlays (e.g. the snack bar) to be rendered behind the native browser UI. Fixes #4650.
1 parent a1e6a1b commit 96549e8

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

src/lib/core/overlay/_overlay.scss

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99
// The container should be the size of the viewport.
1010
top: 0;
1111
left: 0;
12-
13-
// Note: we prefer viewport units, because they aren't being offset by the global scrollbar.
14-
height: 100vh;
15-
width: 100vw;
12+
height: 100%;
13+
width: 100%;
1614
}
1715

1816
// The overlay-container is an invisible element which contains all individual overlays.

src/lib/core/overlay/position/connected-position-strategy.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ describe('ConnectedPositionStrategy', () => {
433433
let overlayRect = overlayElement.getBoundingClientRect();
434434

435435
expect(Math.floor(overlayRect.top)).toBe(Math.floor(originRect.bottom));
436-
expect(Math.floor(overlayRect.right)).toBe(Math.floor(originRect.left));
436+
expect(Math.round(overlayRect.right)).toBe(Math.round(originRect.left));
437437
});
438438

439439
it('should position above, right aligned', () => {
@@ -445,8 +445,8 @@ describe('ConnectedPositionStrategy', () => {
445445
strategy.apply(overlayElement);
446446

447447
let overlayRect = overlayElement.getBoundingClientRect();
448-
expect(Math.floor(overlayRect.bottom)).toBe(Math.floor(originRect.top));
449-
expect(Math.floor(overlayRect.right)).toBe(Math.floor(originRect.right));
448+
expect(Math.round(overlayRect.bottom)).toBe(Math.round(originRect.top));
449+
expect(Math.round(overlayRect.right)).toBe(Math.round(originRect.right));
450450
});
451451

452452
it('should position below, centered', () => {

src/lib/core/overlay/position/connected-position-strategy.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ export class ConnectedPositionStrategy implements PositionStrategy {
354354
overlayRect: ClientRect,
355355
overlayPoint: Point,
356356
pos: ConnectionPositionPair) {
357-
const viewport = this._viewportRuler.getViewportRect();
358357

359358
// We want to set either `top` or `bottom` based on whether the overlay wants to appear above
360359
// or below the origin and the direction in which the element will expand.
@@ -364,7 +363,7 @@ export class ConnectedPositionStrategy implements PositionStrategy {
364363
// from the bottom of the viewport rather than the top.
365364
let y = verticalStyleProperty === 'top' ?
366365
overlayPoint.y :
367-
viewport.height - (overlayPoint.y + overlayRect.height);
366+
document.documentElement.clientHeight - (overlayPoint.y + overlayRect.height);
368367

369368
// We want to set either `left` or `right` based on whether the overlay wants to appear "before"
370369
// or "after" the origin, which determines the direction in which the element will expand.
@@ -381,7 +380,7 @@ export class ConnectedPositionStrategy implements PositionStrategy {
381380
// from the right edge of the viewport rather than the left edge.
382381
let x = horizontalStyleProperty === 'left' ?
383382
overlayPoint.x :
384-
viewport.width - (overlayPoint.x + overlayRect.width);
383+
document.documentElement.clientWidth - (overlayPoint.x + overlayRect.width);
385384

386385

387386
// Reset any existing styles. This is necessary in case the preferred position has

0 commit comments

Comments
 (0)