Skip to content

Commit faa7601

Browse files
crisbetommalerba
authored andcommitted
fix(overlay): error when removing empty string theme (#6306)
Something I ran into while doing #6305. If the previous overlay theme is a blank string, switching to another theme throws an error.
1 parent 8b54715 commit faa7601

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/lib/core/overlay/overlay-container.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ export class OverlayContainer {
2525
get themeClass(): string { return this._themeClass; }
2626
set themeClass(value: string) {
2727
if (this._containerElement) {
28-
this._containerElement.classList.remove(this._themeClass);
28+
if (this._themeClass) {
29+
this._containerElement.classList.remove(this._themeClass);
30+
}
2931

3032
if (value) {
3133
this._containerElement.classList.add(value);

src/lib/core/overlay/overlay.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,11 @@ describe('OverlayContainer theming', () => {
476476
expect(overlayContainerElement.classList).not.toContain('initial-theme');
477477
expect(overlayContainerElement.classList).toContain('new-theme');
478478
});
479+
480+
it('should not throw when switching from a blank theme', () => {
481+
overlayContainer.themeClass = '';
482+
expect(() => overlayContainer.themeClass = 'new-theme').not.toThrow();
483+
});
479484
});
480485

481486
/** Simple component for testing ComponentPortal. */

0 commit comments

Comments
 (0)