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): attempting to position overlay if it was detached immediately after being attached #9507

Merged
merged 1 commit into from
Jan 25, 2018
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
5 changes: 4 additions & 1 deletion src/cdk/overlay/overlay-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ export class OverlayRef implements PortalOutlet {
// before attempting to position it, as the position may depend on the size of the rendered
// content.
this._ngZone.onStable.asObservable().pipe(take(1)).subscribe(() => {
this.updatePosition();
// The overlay could've been detached before the zone has stabilized.
if (this.hasAttached()) {
this.updatePosition();
}
});

// Enable pointer events for the overlay pane element.
Expand Down
16 changes: 16 additions & 0 deletions src/cdk/overlay/overlay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,22 @@ describe('Overlay', () => {

expect(overlayContainerElement.querySelectorAll('.fake-positioned').length).toBe(1);
}));

it('should not apply the position if it detaches before the zone stabilizes', fakeAsync(() => {
config.positionStrategy = new FakePositionStrategy();

const overlayRef = overlay.create(config);

spyOn(config.positionStrategy, 'apply');

overlayRef.attach(componentPortal);
overlayRef.detach();
viewContainerFixture.detectChanges();
tick();

expect(config.positionStrategy.apply).not.toHaveBeenCalled();
}));

});

describe('size', () => {
Expand Down