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
This commit is contained in:
Josip Bojčić
2017-05-30 19:59:35 -04:00
committed by mmalerba
parent 99293d903e
commit 28c936f122
7 changed files with 40 additions and 0 deletions
+1
View File
@@ -15,6 +15,7 @@ export class DialogDemo {
actionsAlignment: string;
config: MdDialogConfig = {
disableClose: false,
panelClass: 'custom-overlay-pane-class',
hasBackdrop: true,
backdropClass: '',
width: '',
+4
View File
@@ -53,6 +53,10 @@ export class OverlayRef implements PortalHost {
this._attachBackdrop();
}
if (this._state.panelClass) {
this._pane.classList.add(this._state.panelClass);
}
return attachResult;
}
+3
View File
@@ -15,6 +15,9 @@ export class OverlayState {
/** Strategy to be used when handling scroll events while the overlay is open. */
scrollStrategy: ScrollStrategy = new NoopScrollStrategy();
/** Custom class to add to the overlay pane. */
panelClass: string = '';
/** Whether the overlay has a backdrop. */
hasBackdrop: boolean = false;
+15
View File
@@ -336,6 +336,21 @@ describe('Overlay', () => {
});
describe('panelClass', () => {
let config: OverlayState;
config = new OverlayState();
config.panelClass = 'custom-panel-class';
it('should apply a custom overlay pane class', () => {
let overlayRef = overlay.create(config);
overlayRef.attach(componentPortal);
viewContainerFixture.detectChanges();
let pane = overlayContainerElement.querySelector('.cdk-overlay-pane') as HTMLElement;
expect(pane.classList).toContain('custom-panel-class');
});
});
describe('scroll strategy', () => {
let fakeScrollStrategy: FakeScrollStrategy;
let config: OverlayState;
+3
View File
@@ -27,6 +27,9 @@ export class MdDialogConfig {
/** The ARIA role of the dialog element. */
role?: DialogRole = 'dialog';
/** Custom class for the overlay pane. */
panelClass?: string = '';
/** Whether the dialog has a backdrop. */
hasBackdrop?: boolean = true;
+13
View File
@@ -455,6 +455,19 @@ describe('MdDialog', () => {
});
});
describe('panelClass option', () => {
it('should have custom panel class', () => {
dialog.open(PizzaMsg, {
panelClass: 'custom-panel-class',
viewContainerRef: testViewContainerRef
});
viewContainerFixture.detectChanges();
expect(overlayContainerElement.querySelector('.custom-panel-class')).toBeTruthy();
});
});
describe('backdropClass option', () => {
it('should have default backdrop class', () => {
dialog.open(PizzaMsg, {
+1
View File
@@ -121,6 +121,7 @@ export class MdDialog {
*/
private _getOverlayState(dialogConfig: MdDialogConfig): OverlayState {
let overlayState = new OverlayState();
overlayState.panelClass = dialogConfig.panelClass;
overlayState.hasBackdrop = dialogConfig.hasBackdrop;
overlayState.scrollStrategy = new BlockScrollStrategy(this._viewportRuler);
if (dialogConfig.backdropClass) {