Skip to content

Commit cf61d58

Browse files
committed
fix(cdk/overlay): safari workaround not working with popovers (#32588)
We had a workaround for Safari's zooming behavior in the CDK overaly, but it had stopped working when we switched to popovers because it relies on measuring the overlay container. These changes fix the issue by making the overlay container visible temporarily so it can be measured. Fixes #32583. (cherry picked from commit 136841e)
1 parent 0d543d2 commit cf61d58

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

src/cdk/overlay/position/flexible-connected-position-strategy.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
253253
this._viewportRect = this._getNarrowedViewportRect();
254254
this._originRect = this._getOriginRect();
255255
this._overlayRect = this._pane.getBoundingClientRect();
256-
this._containerRect = this._overlayContainer.getContainerElement().getBoundingClientRect();
256+
this._containerRect = this._getContainerRect();
257257

258258
const originRect = this._originRect;
259259
const overlayRect = this._overlayRect;
@@ -401,10 +401,11 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
401401
this._originRect = this._getOriginRect();
402402
this._overlayRect = this._pane.getBoundingClientRect();
403403
this._viewportRect = this._getNarrowedViewportRect();
404-
this._containerRect = this._overlayContainer.getContainerElement().getBoundingClientRect();
405-
406-
const originPoint = this._getOriginPoint(this._originRect, this._containerRect, lastPosition);
407-
this._applyPosition(lastPosition, originPoint);
404+
this._containerRect = this._getContainerRect();
405+
this._applyPosition(
406+
lastPosition,
407+
this._getOriginPoint(this._originRect, this._containerRect, lastPosition),
408+
);
408409
} else {
409410
this.apply();
410411
}
@@ -1296,6 +1297,29 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
12961297
width,
12971298
};
12981299
}
1300+
1301+
/** Gets the dimensions of the overlay container. */
1302+
private _getContainerRect(): Dimensions {
1303+
// We have some CSS that hides the overlay container when it's empty. This can happen
1304+
// when a popover-based overlay is open and it hasn't been inserted into the overlay
1305+
// container. If that's the case, make the container temporarily visible so that we
1306+
// can measure it. This information is used to work around some issues in Safari.
1307+
const isInlinePopover =
1308+
this._overlayRef.getConfig().usePopover && this._popoverLocation !== 'global';
1309+
const element = this._overlayContainer.getContainerElement();
1310+
1311+
if (isInlinePopover) {
1312+
element.style.display = 'block';
1313+
}
1314+
1315+
const dimensions = element.getBoundingClientRect();
1316+
1317+
if (isInlinePopover) {
1318+
element.style.display = '';
1319+
}
1320+
1321+
return dimensions;
1322+
}
12991323
}
13001324

13011325
/** A simple (x, y) coordinate. */

0 commit comments

Comments
 (0)