Skip to content

Commit 67729cc

Browse files
committed
fix(overlay): error when trying to add/remove empty string class
Fixes an error being thrown if an empty string is passed as one of the values to `addPanelClass` or `removePanelClass`.
1 parent 88601fa commit 67729cc

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/cdk/overlay/overlay-ref.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,10 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
456456

457457
coerceArray(cssClasses).forEach(cssClass => {
458458
// We can't do a spread here, because IE doesn't support setting multiple classes.
459-
isAdd ? classList.add(cssClass) : classList.remove(cssClass);
459+
// Also trying to add an empty string to a DOMTokenList will throw.
460+
if (cssClass !== '') {
461+
isAdd ? classList.add(cssClass) : classList.remove(cssClass);
462+
}
460463
});
461464
}
462465

src/cdk/overlay/overlay.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,14 @@ describe('Overlay', () => {
418418
expect(() => overlayRef.addPanelClass('custom-class-two')).not.toThrowError();
419419
});
420420

421+
it('should not throw when trying to add or remove and empty string class', () => {
422+
const overlayRef = overlay.create();
423+
overlayRef.attach(componentPortal);
424+
425+
expect(() => overlayRef.addPanelClass('')).not.toThrow();
426+
expect(() => overlayRef.removePanelClass('')).not.toThrow();
427+
});
428+
421429
describe('positioning', () => {
422430
let config: OverlayConfig;
423431

0 commit comments

Comments
 (0)