Skip to content

Commit 176c4cf

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 43a01e9 commit 176c4cf

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
@@ -471,7 +471,10 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
471471

472472
coerceArray(cssClasses).forEach(cssClass => {
473473
// We can't do a spread here, because IE doesn't support setting multiple classes.
474-
isAdd ? classList.add(cssClass) : classList.remove(cssClass);
474+
// Also trying to add an empty string to a DOMTokenList will throw.
475+
if (cssClass) {
476+
isAdd ? classList.add(cssClass) : classList.remove(cssClass);
477+
}
475478
});
476479
}
477480

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)