diff --git a/src/cdk/overlay/overlay-ref.ts b/src/cdk/overlay/overlay-ref.ts index 4abf91a8c702..75585e874b6f 100644 --- a/src/cdk/overlay/overlay-ref.ts +++ b/src/cdk/overlay/overlay-ref.ts @@ -471,7 +471,10 @@ export class OverlayRef implements PortalOutlet, OverlayReference { coerceArray(cssClasses).forEach(cssClass => { // We can't do a spread here, because IE doesn't support setting multiple classes. - isAdd ? classList.add(cssClass) : classList.remove(cssClass); + // Also trying to add an empty string to a DOMTokenList will throw. + if (cssClass) { + isAdd ? classList.add(cssClass) : classList.remove(cssClass); + } }); } diff --git a/src/cdk/overlay/overlay.spec.ts b/src/cdk/overlay/overlay.spec.ts index 0a3a54ce88a6..95a2a03223a7 100644 --- a/src/cdk/overlay/overlay.spec.ts +++ b/src/cdk/overlay/overlay.spec.ts @@ -418,6 +418,14 @@ describe('Overlay', () => { expect(() => overlayRef.addPanelClass('custom-class-two')).not.toThrowError(); }); + it('should not throw when trying to add or remove and empty string class', () => { + const overlayRef = overlay.create(); + overlayRef.attach(componentPortal); + + expect(() => overlayRef.addPanelClass('')).not.toThrow(); + expect(() => overlayRef.removePanelClass('')).not.toThrow(); + }); + describe('positioning', () => { let config: OverlayConfig;