fix(overlay): remove panelClass when the overlay is detached (#12142)

Removes the `panelClass` when the overlay is detached. This ensures that any overlay styling that targets the panel isn't left behind while the panel is detached.

Relates to #12099.
This commit is contained in:
Kristiyan Kostadinov
2018-07-12 16:42:06 +02:00
committed by Jeremy Elbourn
parent 04934b43e3
commit 79bacf2019
2 changed files with 25 additions and 1 deletions
+5 -1
View File
@@ -164,12 +164,16 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
this._config.scrollStrategy.disable();
}
if (this._config.panelClass) {
this._toggleClasses(this._pane, this._config.panelClass, false);
}
const detachmentResult = this._portalOutlet.detach();
// Only emit after everything is detached.
this._detachments.next();
// Remove this overlay from keyboard dispatcher tracking
// Remove this overlay from keyboard dispatcher tracking.
this._keyboardDispatcher.remove(this);
return detachmentResult;
+20
View File
@@ -628,6 +628,26 @@ describe('Overlay', () => {
expect(pane.classList).toContain('custom-class-one');
expect(pane.classList).toContain('custom-class-two');
});
it('should remove the custom panel class when the overlay is detached', () => {
const config = new OverlayConfig({panelClass: 'custom-panel-class'});
const overlayRef = overlay.create(config);
overlayRef.attach(componentPortal);
viewContainerFixture.detectChanges();
const pane = overlayContainerElement.querySelector('.cdk-overlay-pane') as HTMLElement;
expect(pane.classList).toContain('custom-panel-class');
overlayRef.detach();
viewContainerFixture.detectChanges();
expect(pane.classList).not.toContain('custom-panel-class');
overlayRef.attach(componentPortal);
viewContainerFixture.detectChanges();
expect(pane.classList).toContain('custom-panel-class');
});
});
describe('scroll strategy', () => {