Skip to content

fix(overlay): incorrectly calculating position when page is scrolled horizontally and overlay is anchored to the right #16235

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 @@ -1927,6 +1927,82 @@ describe('FlexibleConnectedPositionStrategy', () => {
expect(Math.floor(overlayRect.bottom)).toBe(Math.floor(originRect.bottom));
});

it('should position an overlay that is flowing to the left correctly on a page that is ' +
'scrolled horizontally', () => {
const veryLargeElement: HTMLElement = document.createElement('div');
veryLargeElement.style.width = '4000px';
veryLargeElement.style.height = '4000px';
document.body.appendChild(veryLargeElement);
window.scroll(2100, 0);

originElement.style.position = 'absolute';
originElement.style.top = '100px';
originElement.style.left = '300px';

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

attachOverlay({positionStrategy});

const originRect = originElement.getBoundingClientRect();
const overlayRect = overlayRef.overlayElement.getBoundingClientRect();

expect(Math.floor(overlayRect.right)).toBe(Math.floor(originRect.right));
expect(Math.floor(overlayRect.top)).toBe(Math.floor(originRect.top));

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

it('should size the bounding box that is flowing to the left correctly on a page that is ' +
'scrolled horizontally', () => {
const veryLargeElement: HTMLElement = document.createElement('div');
veryLargeElement.style.width = '4000px';
veryLargeElement.style.height = '4000px';
document.body.appendChild(veryLargeElement);
window.scroll(100, 0);

originElement.style.position = 'absolute';
originElement.style.top = '100px';
originElement.style.left = '300px';

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

attachOverlay({positionStrategy});

let originRect = originElement.getBoundingClientRect();
let boundingBoxRect = overlayRef.hostElement.getBoundingClientRect();

expect(Math.floor(originRect.right)).toBe(Math.floor(boundingBoxRect.width));

window.scroll(200, 0);
overlayRef.updatePosition();

originRect = originElement.getBoundingClientRect();
boundingBoxRect = overlayRef.hostElement.getBoundingClientRect();

expect(Math.floor(originRect.right)).toBe(Math.floor(boundingBoxRect.width));

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


});

describe('onPositionChange with scrollable view properties', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,8 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
let width: number, left: number, right: number;

if (isBoundedByLeftViewportEdge) {
right = viewport.right - origin.x + this._viewportMargin;
width = origin.x - viewport.left;
right = viewport.width - origin.x + this._viewportMargin;
width = origin.x - this._viewportMargin;
} else if (isBoundedByRightViewportEdge) {
left = origin.x;
width = viewport.right - origin.x;
Expand Down