Skip to content

Commit 28c936f

Browse files
Josip Bojčićmmalerba
Josip Bojčić
authored andcommitted
feat(dialog): custom class option #4718 #4012 (#4722)
* feat(dialog): custom class option Extend dialog config options to allow custom dialog class. Custom class enables media queries. #4718 #4012 * refactor(dialog): custom class option. Changed custom class config option name. Remove unnecessary class removal on detach. #4718 #4012 * test(dialog): custom class option. Added missing unit test to check if overlay pane has custom panel class. #4718 #4012 * refactor(dialog): custom class option. Change wrong comment. Remove unnecessary beforeEach from test. #4718 #4012
1 parent 99293d9 commit 28c936f

File tree

7 files changed

+40
-0
lines changed

7 files changed

+40
-0
lines changed

src/demo-app/dialog/dialog-demo.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export class DialogDemo {
1515
actionsAlignment: string;
1616
config: MdDialogConfig = {
1717
disableClose: false,
18+
panelClass: 'custom-overlay-pane-class',
1819
hasBackdrop: true,
1920
backdropClass: '',
2021
width: '',

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ export class OverlayRef implements PortalHost {
5353
this._attachBackdrop();
5454
}
5555

56+
if (this._state.panelClass) {
57+
this._pane.classList.add(this._state.panelClass);
58+
}
59+
5660
return attachResult;
5761
}
5862

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export class OverlayState {
1515
/** Strategy to be used when handling scroll events while the overlay is open. */
1616
scrollStrategy: ScrollStrategy = new NoopScrollStrategy();
1717

18+
/** Custom class to add to the overlay pane. */
19+
panelClass: string = '';
20+
1821
/** Whether the overlay has a backdrop. */
1922
hasBackdrop: boolean = false;
2023

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,21 @@ describe('Overlay', () => {
336336

337337
});
338338

339+
describe('panelClass', () => {
340+
let config: OverlayState;
341+
config = new OverlayState();
342+
config.panelClass = 'custom-panel-class';
343+
344+
it('should apply a custom overlay pane class', () => {
345+
let overlayRef = overlay.create(config);
346+
overlayRef.attach(componentPortal);
347+
viewContainerFixture.detectChanges();
348+
349+
let pane = overlayContainerElement.querySelector('.cdk-overlay-pane') as HTMLElement;
350+
expect(pane.classList).toContain('custom-panel-class');
351+
});
352+
});
353+
339354
describe('scroll strategy', () => {
340355
let fakeScrollStrategy: FakeScrollStrategy;
341356
let config: OverlayState;

src/lib/dialog/dialog-config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export class MdDialogConfig {
2727
/** The ARIA role of the dialog element. */
2828
role?: DialogRole = 'dialog';
2929

30+
/** Custom class for the overlay pane. */
31+
panelClass?: string = '';
32+
3033
/** Whether the dialog has a backdrop. */
3134
hasBackdrop?: boolean = true;
3235

src/lib/dialog/dialog.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,19 @@ describe('MdDialog', () => {
455455
});
456456
});
457457

458+
describe('panelClass option', () => {
459+
it('should have custom panel class', () => {
460+
dialog.open(PizzaMsg, {
461+
panelClass: 'custom-panel-class',
462+
viewContainerRef: testViewContainerRef
463+
});
464+
465+
viewContainerFixture.detectChanges();
466+
467+
expect(overlayContainerElement.querySelector('.custom-panel-class')).toBeTruthy();
468+
});
469+
});
470+
458471
describe('backdropClass option', () => {
459472
it('should have default backdrop class', () => {
460473
dialog.open(PizzaMsg, {

src/lib/dialog/dialog.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export class MdDialog {
121121
*/
122122
private _getOverlayState(dialogConfig: MdDialogConfig): OverlayState {
123123
let overlayState = new OverlayState();
124+
overlayState.panelClass = dialogConfig.panelClass;
124125
overlayState.hasBackdrop = dialogConfig.hasBackdrop;
125126
overlayState.scrollStrategy = new BlockScrollStrategy(this._viewportRuler);
126127
if (dialogConfig.backdropClass) {

0 commit comments

Comments
 (0)