Skip to content

Commit f96fcc9

Browse files
crisbetovictoriaaa234
authored andcommitted
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.
1 parent 183ee52 commit f96fcc9

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/cdk/overlay/overlay-ref.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,16 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
164164
this._config.scrollStrategy.disable();
165165
}
166166

167+
if (this._config.panelClass) {
168+
this._toggleClasses(this._pane, this._config.panelClass, false);
169+
}
170+
167171
const detachmentResult = this._portalOutlet.detach();
168172

169173
// Only emit after everything is detached.
170174
this._detachments.next();
171175

172-
// Remove this overlay from keyboard dispatcher tracking
176+
// Remove this overlay from keyboard dispatcher tracking.
173177
this._keyboardDispatcher.remove(this);
174178

175179
return detachmentResult;

src/cdk/overlay/overlay.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,26 @@ describe('Overlay', () => {
628628
expect(pane.classList).toContain('custom-class-one');
629629
expect(pane.classList).toContain('custom-class-two');
630630
});
631+
632+
it('should remove the custom panel class when the overlay is detached', () => {
633+
const config = new OverlayConfig({panelClass: 'custom-panel-class'});
634+
const overlayRef = overlay.create(config);
635+
636+
overlayRef.attach(componentPortal);
637+
viewContainerFixture.detectChanges();
638+
639+
const pane = overlayContainerElement.querySelector('.cdk-overlay-pane') as HTMLElement;
640+
expect(pane.classList).toContain('custom-panel-class');
641+
642+
overlayRef.detach();
643+
viewContainerFixture.detectChanges();
644+
expect(pane.classList).not.toContain('custom-panel-class');
645+
646+
overlayRef.attach(componentPortal);
647+
viewContainerFixture.detectChanges();
648+
expect(pane.classList).toContain('custom-panel-class');
649+
});
650+
631651
});
632652

633653
describe('scroll strategy', () => {

0 commit comments

Comments
 (0)