Skip to content

Commit 8f60b62

Browse files
authored
fix(cdk/overlay): fix overlay margin in isBoundedByLeftViewportEdge ('left-ward') mode (#28233)
1 parent 5a94150 commit 8f60b62

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,6 +2000,31 @@ describe('FlexibleConnectedPositionStrategy', () => {
20002000
expect(Math.floor(overlayRect.top)).toBe(viewportMargin);
20012001
});
20022002

2003+
it('should calculate the right offset correctly with a viewport margin', async () => {
2004+
const viewportMargin = 5;
2005+
const right = 20;
2006+
2007+
originElement.style.right = `${right}px`;
2008+
originElement.style.top = `200px`;
2009+
2010+
positionStrategy
2011+
.withFlexibleDimensions()
2012+
.withPush(false)
2013+
.withViewportMargin(viewportMargin)
2014+
.withPositions([
2015+
{
2016+
originX: 'end',
2017+
originY: 'top',
2018+
overlayX: 'end',
2019+
overlayY: 'bottom',
2020+
},
2021+
]);
2022+
2023+
attachOverlay({positionStrategy});
2024+
2025+
expect(overlayRef.hostElement.style.right).toBe(`${right}px`);
2026+
});
2027+
20032028
it('should center flexible overlay with push on a scrolled page', () => {
20042029
const veryLargeElement = document.createElement('div');
20052030

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
815815
let width: number, left: number, right: number;
816816

817817
if (isBoundedByLeftViewportEdge) {
818-
right = viewport.width - origin.x + this._viewportMargin;
818+
right = viewport.width - origin.x + this._viewportMargin * 2;
819819
width = origin.x - this._viewportMargin;
820820
} else if (isBoundedByRightViewportEdge) {
821821
left = origin.x;

0 commit comments

Comments
 (0)