Skip to content
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

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

Merged
merged 1 commit into from
Nov 7, 2016
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
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