Skip to content

fix(overlay): not sizing flexible overlay correctly when opening downwards on a scrollable page #14672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1777,6 +1777,47 @@ describe('FlexibleConnectedPositionStrategy', () => {
document.body.removeChild(veryLargeElement);
});

it('should size the bounding box correctly when opening downwards on a scrolled page', () => {
const viewportMargin = 10;
const veryLargeElement: HTMLElement = document.createElement('div');
veryLargeElement.style.width = '4000px';
veryLargeElement.style.height = '4000px';
document.body.appendChild(veryLargeElement);
window.scroll(2100, 2100);

originElement.style.position = 'fixed';
originElement.style.top = '100px';
originElement.style.left = '200px';

positionStrategy
.withFlexibleDimensions()
.withPush(false)
.withViewportMargin(viewportMargin)
.withPositions([{
overlayY: 'top',
overlayX: 'start',
originY: 'bottom',
originX: 'start'
}]);

attachOverlay({positionStrategy});

const boundingBox = overlayContainer
.getContainerElement()
.querySelector('.cdk-overlay-connected-position-bounding-box') as HTMLElement;

// Use the `documentElement` here to determine the viewport
// height since it's what is used by the overlay.
const viewportHeight = document.documentElement!.clientHeight - (2 * viewportMargin);
const originRect = originElement.getBoundingClientRect();
const boundingBoxRect = boundingBox.getBoundingClientRect();

expect(Math.floor(boundingBoxRect.height))
.toBe(Math.floor(viewportHeight - originRect.bottom + viewportMargin));

window.scroll(0, 0);
document.body.removeChild(veryLargeElement);
});

});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
if (position.overlayY === 'top') {
// Overlay is opening "downward" and thus is bound by the bottom viewport edge.
top = origin.y;
height = viewport.bottom - origin.y;
height = viewport.height - top + this._viewportMargin;
} else if (position.overlayY === 'bottom') {
// Overlay is opening "upward" and thus is bound by the top viewport edge. We need to add
// the viewport margin back in, because the viewport rect is narrowed down to remove the
Expand Down