Skip to content

Commit

Permalink
feat(dialog): custom class option
Browse files Browse the repository at this point in the history
Extend dialog config options to allow custom dialog class. Custom class enables media queries.

angular#4718 angular#4012
  • Loading branch information
jbojcic1 committed May 22, 2017
1 parent c946631 commit 07442eb
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/demo-app/dialog/dialog-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class DialogDemo {
actionsAlignment: string;
config: MdDialogConfig = {
disableClose: false,
dialogClass: 'custom-dialog-class',
hasBackdrop: true,
backdropClass: '',
width: '',
Expand Down
5 changes: 5 additions & 0 deletions src/lib/core/overlay/overlay-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export class OverlayRef implements PortalHost {
this._attachBackdrop();
}

if (this._state.dialogClass) {
this._pane.classList.add(this._state.dialogClass);
}

return attachResult;
}

Expand All @@ -69,6 +73,7 @@ export class OverlayRef implements PortalHost {
this._togglePointerEvents(false);
this._state.scrollStrategy.disable();
this._detachments.next();
this._pane.classList.remove(this._state.dialogClass);

return this._portalHost.detach();
}
Expand Down
3 changes: 3 additions & 0 deletions src/lib/core/overlay/overlay-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 dialog */
dialogClass: string = '';

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

Expand Down
3 changes: 3 additions & 0 deletions src/lib/dialog/dialog-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export class MdDialogConfig {
/** The ARIA role of the dialog element. */
role?: DialogRole = 'dialog';

/** Custom class for the dialog, */
dialogClass?: string = '';

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

Expand Down
1 change: 1 addition & 0 deletions src/lib/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export class MdDialog {
*/
private _getOverlayState(dialogConfig: MdDialogConfig): OverlayState {
let overlayState = new OverlayState();
overlayState.dialogClass = dialogConfig.dialogClass;
overlayState.hasBackdrop = dialogConfig.hasBackdrop;
overlayState.scrollStrategy = new BlockScrollStrategy(this._viewportRuler);
if (dialogConfig.backdropClass) {
Expand Down

0 comments on commit 07442eb

Please sign in to comment.