mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
committed by
Jeremy Elbourn
parent
04934b43e3
commit
79bacf2019
@@ -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;
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user