fix(overlay): fix connected position calculation while scrolled (#1732)

This commit is contained in:
Kara
2016-11-07 15:48:55 -08:00
committed by Jeremy Elbourn
parent a0d85d8793
commit 2de461e8ca
2 changed files with 19 additions and 6 deletions
@@ -20,6 +20,7 @@ describe('ConnectedPositionStrategy', () => {
let originElement: HTMLElement;
let overlayElement: HTMLElement;
let overlayContainerElement: HTMLElement;
let strategy: ConnectedPositionStrategy;
let fakeElementRef: ElementRef;
let fakeViewportRuler: FakeViewportRuler;
@@ -34,9 +35,11 @@ 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());
@@ -44,7 +47,7 @@ describe('ConnectedPositionStrategy', () => {
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;
@@ -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 {
@@ -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.