From faa760104f80f494339bcce9c662109266816aa8 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Mon, 7 Aug 2017 23:23:47 +0200 Subject: [PATCH] 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. --- src/lib/core/overlay/overlay-container.ts | 4 +++- src/lib/core/overlay/overlay.spec.ts | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib/core/overlay/overlay-container.ts b/src/lib/core/overlay/overlay-container.ts index 390ea3f48bcf..a97eb9a28d76 100644 --- a/src/lib/core/overlay/overlay-container.ts +++ b/src/lib/core/overlay/overlay-container.ts @@ -25,7 +25,9 @@ export class OverlayContainer { get themeClass(): string { return this._themeClass; } set themeClass(value: string) { if (this._containerElement) { - this._containerElement.classList.remove(this._themeClass); + if (this._themeClass) { + this._containerElement.classList.remove(this._themeClass); + } if (value) { this._containerElement.classList.add(value); diff --git a/src/lib/core/overlay/overlay.spec.ts b/src/lib/core/overlay/overlay.spec.ts index cc96eaa8146d..fc31e3f9d28a 100644 --- a/src/lib/core/overlay/overlay.spec.ts +++ b/src/lib/core/overlay/overlay.spec.ts @@ -476,6 +476,11 @@ describe('OverlayContainer theming', () => { expect(overlayContainerElement.classList).not.toContain('initial-theme'); expect(overlayContainerElement.classList).toContain('new-theme'); }); + + it('should not throw when switching from a blank theme', () => { + overlayContainer.themeClass = ''; + expect(() => overlayContainer.themeClass = 'new-theme').not.toThrow(); + }); }); /** Simple component for testing ComponentPortal. */