Skip to content

Commit a190de7

Browse files
crisbetommalerba
authored andcommitted
feat(overlay): support setting multiple panel classes (#6326)
Allows for more than one class to be added via the `panelClass` option. Fixes #6318.
1 parent 18c6689 commit a190de7

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ export class OverlayRef implements PortalHost {
6060
}
6161

6262
if (this._state.panelClass) {
63-
this._pane.classList.add(this._state.panelClass);
63+
// We can't do a spread here, because IE doesn't support setting multiple classes.
64+
if (Array.isArray(this._state.panelClass)) {
65+
this._state.panelClass.forEach(cls => this._pane.classList.add(cls));
66+
} else {
67+
this._pane.classList.add(this._state.panelClass);
68+
}
6469
}
6570

6671
// Only emit the `attachments` event once all other setup is done.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class OverlayState {
2424
scrollStrategy: ScrollStrategy = new NoopScrollStrategy();
2525

2626
/** Custom class to add to the overlay pane. */
27-
panelClass?: string = '';
27+
panelClass?: string | string[] = '';
2828

2929
/** Whether the overlay has a backdrop. */
3030
hasBackdrop?: boolean = false;

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -395,18 +395,29 @@ describe('Overlay', () => {
395395
});
396396

397397
describe('panelClass', () => {
398-
let config: OverlayState;
399-
config = new OverlayState();
400-
config.panelClass = 'custom-panel-class';
401-
402398
it('should apply a custom overlay pane class', () => {
403-
let overlayRef = overlay.create(config);
404-
overlayRef.attach(componentPortal);
399+
const config = new OverlayState();
400+
401+
config.panelClass = 'custom-panel-class';
402+
overlay.create(config).attach(componentPortal);
405403
viewContainerFixture.detectChanges();
406404

407-
let pane = overlayContainerElement.querySelector('.cdk-overlay-pane') as HTMLElement;
405+
const pane = overlayContainerElement.querySelector('.cdk-overlay-pane') as HTMLElement;
408406
expect(pane.classList).toContain('custom-panel-class');
409407
});
408+
409+
it('should be able to apply multiple classes', () => {
410+
const config = new OverlayState();
411+
412+
config.panelClass = ['custom-class-one', 'custom-class-two'];
413+
overlay.create(config).attach(componentPortal);
414+
viewContainerFixture.detectChanges();
415+
416+
const pane = overlayContainerElement.querySelector('.cdk-overlay-pane') as HTMLElement;
417+
418+
expect(pane.classList).toContain('custom-class-one');
419+
expect(pane.classList).toContain('custom-class-two');
420+
});
410421
});
411422

412423
describe('scroll strategy', () => {

src/lib/dialog/dialog-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class MdDialogConfig {
4040
role?: DialogRole = 'dialog';
4141

4242
/** Custom class for the overlay pane. */
43-
panelClass?: string = '';
43+
panelClass?: string | string[] = '';
4444

4545
/** Whether the dialog has a backdrop. */
4646
hasBackdrop?: boolean = true;

0 commit comments

Comments
 (0)