Skip to content

Commit 2de461e

Browse files
karajelbourn
authored andcommitted
fix(overlay): fix connected position calculation while scrolled (#1732)
1 parent a0d85d8 commit 2de461e

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/lib/core/overlay/position/connected-position-strategy.spec.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ describe('ConnectedPositionStrategy', () => {
2020

2121
let originElement: HTMLElement;
2222
let overlayElement: HTMLElement;
23+
let overlayContainerElement: HTMLElement;
2324
let strategy: ConnectedPositionStrategy;
2425
let fakeElementRef: ElementRef;
2526
let fakeViewportRuler: FakeViewportRuler;
@@ -34,17 +35,19 @@ describe('ConnectedPositionStrategy', () => {
3435

3536
// The origin and overlay elements need to be in the document body in order to have geometry.
3637
originElement = createPositionedBlockElement();
38+
overlayContainerElement = createFixedElement();
3739
overlayElement = createPositionedBlockElement();
3840
document.body.appendChild(originElement);
39-
document.body.appendChild(overlayElement);
41+
document.body.appendChild(overlayContainerElement);
42+
overlayContainerElement.appendChild(overlayElement);
4043

4144
fakeElementRef = new FakeElementRef(originElement);
4245
positionBuilder = new OverlayPositionBuilder(new ViewportRuler());
4346
});
4447

4548
afterEach(() => {
4649
document.body.removeChild(originElement);
47-
document.body.removeChild(overlayElement);
50+
document.body.removeChild(overlayContainerElement);
4851

4952
// Reset the origin geometry after each test so we don't accidently keep state between tests.
5053
originRect = null;
@@ -359,6 +362,18 @@ function createPositionedBlockElement() {
359362
return element;
360363
}
361364

365+
/** Creates an position: fixed element that spans the screen size. */
366+
function createFixedElement() {
367+
let element = document.createElement('div');
368+
element.style.position = 'fixed';
369+
element.style.top = '0';
370+
element.style.left = '0';
371+
element.style.width = `100%`;
372+
element.style.height = `100%`;
373+
element.style.zIndex = '100';
374+
return element;
375+
}
376+
362377

363378
/** Fake implementation of ViewportRuler that just returns the previously given ClientRect. */
364379
class FakeViewportRuler implements ViewportRuler {

src/lib/core/overlay/position/connected-position-strategy.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,8 @@ export class ConnectedPositionStrategy implements PositionStrategy {
217217
* @param overlayPoint
218218
*/
219219
private _setElementPosition(element: HTMLElement, overlayPoint: Point) {
220-
let scrollPos = this._viewportRuler.getViewportScrollPosition();
221-
222-
let x = overlayPoint.x + scrollPos.left;
223-
let y = overlayPoint.y + scrollPos.top;
220+
let x = overlayPoint.x;
221+
let y = overlayPoint.y;
224222

225223
// TODO(jelbourn): we don't want to always overwrite the transform property here,
226224
// because it will need to be used for animations.

0 commit comments

Comments
 (0)