Skip to content

Commit 2e7ecd1

Browse files
committed
fix(cdk/overlay): flexible overlay screen overflow
Add max-height to flexible positioned overlays to prevent them from overflowing out of the scrollable window. Fixes #13829 Fixes #18901
1 parent 622152d commit 2e7ecd1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
926926
right: '',
927927
position: '',
928928
transform: '',
929+
maxHeight: '',
929930
} as CSSStyleDeclaration);
930931
}
931932

@@ -1004,13 +1005,17 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
10041005

10051006
// We want to set either `top` or `bottom` based on whether the overlay wants to appear
10061007
// above or below the origin and the direction in which the element will expand.
1008+
const documentHeight = this._document.documentElement!.clientHeight;
10071009
if (position.overlayY === 'bottom') {
10081010
// When using `bottom`, we adjust the y position such that it is the distance
10091011
// from the bottom of the viewport rather than the top.
1010-
const documentHeight = this._document.documentElement!.clientHeight;
10111012
styles.bottom = `${documentHeight - (overlayPoint.y + this._overlayRect.height)}px`;
1013+
styles.maxHeight = `${overlayPoint.y + this._overlayRect.height + scrollPosition.top}px`;
10121014
} else {
1015+
const remainingScroll =
1016+
this._document.documentElement!.scrollHeight - documentHeight - scrollPosition.top;
10131017
styles.top = coerceCssPixelValue(overlayPoint.y);
1018+
styles.maxHeight = `${documentHeight - overlayPoint.y + remainingScroll}px`;
10141019
}
10151020

10161021
return styles;

0 commit comments

Comments
 (0)