Skip to content

fix(overlay): restore previous host element before attaching #17855

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

Merged
merged 1 commit into from
Jan 24, 2020
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
8 changes: 4 additions & 4 deletions src/cdk/overlay/overlay-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
attach(portal: Portal<any>): any {
let attachResult = this._portalOutlet.attach(portal);

if (this._positionStrategy) {
this._positionStrategy.attach(this);
}

// Update the pane element with the given configuration.
if (!this._host.parentElement && this._previousHostParent) {
this._previousHostParent.appendChild(this._host);
}

if (this._positionStrategy) {
this._positionStrategy.attach(this);
}

this._updateStackingOrder();
this._updateElementSize();
this._updateElementDirection();
Expand Down
23 changes: 23 additions & 0 deletions src/cdk/overlay/overlay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,29 @@ describe('Overlay', () => {
expect(overlayContainerElement.querySelectorAll('.fake-positioned').length).toBe(1);
}));

it('should have the overlay in the DOM in position strategy when reattaching', fakeAsync(() => {
let overlayPresentInDom = false;

config.positionStrategy = {
attach: (ref: OverlayRef) => overlayPresentInDom = !!ref.hostElement.parentElement,
apply: () => {},
dispose: () => {}
};

const overlayRef = overlay.create(config);

overlayRef.attach(componentPortal);
expect(overlayPresentInDom).toBeTruthy('Expected host element to be attached to the DOM.');

overlayRef.detach();
zone.simulateZoneExit();
tick();

overlayRef.attach(componentPortal);

expect(overlayPresentInDom).toBeTruthy('Expected host element to be attached to the DOM.');
}));

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

Expand Down