Skip to content

Commit 52e15bc

Browse files
committed
fix(overlay): restore previous host element before attaching
1 parent ab0f30d commit 52e15bc

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/cdk/overlay/overlay-ref.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
114114
attach(portal: Portal<any>): any {
115115
let attachResult = this._portalOutlet.attach(portal);
116116

117-
if (this._positionStrategy) {
118-
this._positionStrategy.attach(this);
119-
}
120-
121117
// Update the pane element with the given configuration.
122118
if (!this._host.parentElement && this._previousHostParent) {
123119
this._previousHostParent.appendChild(this._host);
124120
}
125121

122+
if (this._positionStrategy) {
123+
this._positionStrategy.attach(this);
124+
}
125+
126126
this._updateStackingOrder();
127127
this._updateElementSize();
128128
this._updateElementDirection();

src/cdk/overlay/overlay.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,27 @@ describe('Overlay', () => {
444444
expect(overlayContainerElement.querySelectorAll('.fake-positioned').length).toBe(1);
445445
}));
446446

447+
it('should have the overlay in the DOM in position strategy when reattaching', fakeAsync(() => {
448+
config.positionStrategy = {
449+
attach(ref: OverlayRef): void {
450+
expect(ref.hostElement.parentElement)
451+
.toBeTruthy('Expected host element to be attached to the DOM.');
452+
},
453+
apply(): void {},
454+
dispose(): void {}
455+
};
456+
457+
const overlayRef = overlay.create(config);
458+
459+
overlayRef.attach(componentPortal);
460+
461+
overlayRef.detach();
462+
zone.simulateZoneExit();
463+
tick();
464+
465+
overlayRef.attach(componentPortal);
466+
}));
467+
447468
it('should not apply the position if it detaches before the zone stabilizes', fakeAsync(() => {
448469
config.positionStrategy = new FakePositionStrategy();
449470

0 commit comments

Comments
 (0)