Skip to content

Commit

Permalink
fix(overlay): fix connected position calculation while scrolled (#1732)
Browse files Browse the repository at this point in the history
  • Loading branch information
kara authored and jelbourn committed Nov 7, 2016
1 parent a0d85d8 commit 2de461e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
19 changes: 17 additions & 2 deletions src/lib/core/overlay/position/connected-position-strategy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('ConnectedPositionStrategy', () => {

let originElement: HTMLElement;
let overlayElement: HTMLElement;
let overlayContainerElement: HTMLElement;
let strategy: ConnectedPositionStrategy;
let fakeElementRef: ElementRef;
let fakeViewportRuler: FakeViewportRuler;
Expand All @@ -34,17 +35,19 @@ describe('ConnectedPositionStrategy', () => {

// The origin and overlay elements need to be in the document body in order to have geometry.
originElement = createPositionedBlockElement();
overlayContainerElement = createFixedElement();
overlayElement = createPositionedBlockElement();
document.body.appendChild(originElement);
document.body.appendChild(overlayElement);
document.body.appendChild(overlayContainerElement);
overlayContainerElement.appendChild(overlayElement);

fakeElementRef = new FakeElementRef(originElement);
positionBuilder = new OverlayPositionBuilder(new ViewportRuler());
});

afterEach(() => {
document.body.removeChild(originElement);
document.body.removeChild(overlayElement);
document.body.removeChild(overlayContainerElement);

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

/** Creates an position: fixed element that spans the screen size. */
function createFixedElement() {
let element = document.createElement('div');
element.style.position = 'fixed';
element.style.top = '0';
element.style.left = '0';
element.style.width = `100%`;
element.style.height = `100%`;
element.style.zIndex = '100';
return element;
}


/** Fake implementation of ViewportRuler that just returns the previously given ClientRect. */
class FakeViewportRuler implements ViewportRuler {
Expand Down
6 changes: 2 additions & 4 deletions src/lib/core/overlay/position/connected-position-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,8 @@ export class ConnectedPositionStrategy implements PositionStrategy {
* @param overlayPoint
*/
private _setElementPosition(element: HTMLElement, overlayPoint: Point) {
let scrollPos = this._viewportRuler.getViewportScrollPosition();

let x = overlayPoint.x + scrollPos.left;
let y = overlayPoint.y + scrollPos.top;
let x = overlayPoint.x;
let y = overlayPoint.y;

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

0 comments on commit 2de461e

Please sign in to comment.