Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dialog): add hasBackdrop and backdropClass options to dialog config #2822

Merged
merged 2 commits into from
Apr 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/demo-app/dialog/dialog-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ <h2>Dialog position</h2>
</md-input-container>
</p>

<h2>Dialog backdrop</h2>

<p>
<md-input-container>
<input mdInput [(ngModel)]="config.backdropClass" placeholder="Backdrop class">
</md-input-container>
</p>

<md-checkbox [(ngModel)]="config.hasBackdrop">Has backdrop</md-checkbox>

<h2>Other options</h2>

<p>
Expand Down
2 changes: 2 additions & 0 deletions src/demo-app/dialog/dialog-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export class DialogDemo {
actionsAlignment: string;
config: MdDialogConfig = {
disableClose: false,
hasBackdrop: true,
backdropClass: '',
width: '',
height: '',
position: {
Expand Down
6 changes: 6 additions & 0 deletions src/lib/dialog/dialog-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ export class MdDialogConfig {
/** The ARIA role of the dialog element. */
role?: DialogRole = 'dialog';

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

/** Custom class for the backdrop, */
backdropClass?: string = '';

/** Whether the user can use escape or clicking outside to close a modal. */
disableClose?: boolean = false;

Expand Down
48 changes: 48 additions & 0 deletions src/lib/dialog/dialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,54 @@ describe('MdDialog', () => {
});
});

describe('hasBackdrop option', () => {
it('should have a backdrop', () => {
dialog.open(PizzaMsg, {
hasBackdrop: true,
viewContainerRef: testViewContainerRef
});

viewContainerFixture.detectChanges();

expect(overlayContainerElement.querySelector('.cdk-overlay-backdrop')).toBeTruthy();
});

it('should not have a backdrop', () => {
dialog.open(PizzaMsg, {
hasBackdrop: false,
viewContainerRef: testViewContainerRef
});

viewContainerFixture.detectChanges();

expect(overlayContainerElement.querySelector('.cdk-overlay-backdrop')).toBeFalsy();
});
});

describe('backdropClass option', () => {
it('should have default backdrop class', () => {
dialog.open(PizzaMsg, {
backdropClass: '',
viewContainerRef: testViewContainerRef
});

viewContainerFixture.detectChanges();

expect(overlayContainerElement.querySelector('.cdk-overlay-dark-backdrop')).toBeTruthy();
});

it('should have custom backdrop class', () => {
dialog.open(PizzaMsg, {
backdropClass: 'custom-backdrop-class',
viewContainerRef: testViewContainerRef
});

viewContainerFixture.detectChanges();

expect(overlayContainerElement.querySelector('.custom-backdrop-class')).toBeTruthy();
});
});

describe('focus management', () => {

// When testing focus, all of the elements must be in the DOM.
Expand Down
5 changes: 4 additions & 1 deletion src/lib/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ export class MdDialog {
*/
private _getOverlayState(dialogConfig: MdDialogConfig): OverlayState {
let overlayState = new OverlayState();
overlayState.hasBackdrop = true;
overlayState.hasBackdrop = dialogConfig.hasBackdrop;
if (dialogConfig.backdropClass) {
overlayState.backdropClass = dialogConfig.backdropClass;
}
overlayState.positionStrategy = this._overlay.position().global();

return overlayState;
Expand Down