Skip to content

Commit

Permalink
feat(dialog): expose backdrop clicks (#6511)
Browse files Browse the repository at this point in the history
  • Loading branch information
willshowell authored and kara committed Aug 22, 2017
1 parent 6cdbf36 commit df28c3d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/lib/dialog/dialog-ref.ts
Expand Up @@ -89,6 +89,13 @@ export class MdDialogRef<T> {
return this._beforeClose.asObservable();
}

/**
* Gets an observable that emits when the overlay's backdrop has been clicked.
*/
backdropClick(): Observable<void> {
return this._overlayRef.backdropClick();
}

/**
* Updates the dialog's position.
* @param position New dialog position.
Expand Down
24 changes: 24 additions & 0 deletions src/lib/dialog/dialog.spec.ts
Expand Up @@ -237,6 +237,30 @@ describe('MdDialog', () => {
});
}));

it('should emit the backdropClick stream when clicking on the overlay backdrop', async(() => {
const dialogRef = dialog.open(PizzaMsg, {
viewContainerRef: testViewContainerRef
});

const spy = jasmine.createSpy('backdropClick spy');
dialogRef.backdropClick().subscribe(spy);

viewContainerFixture.detectChanges();

let backdrop = overlayContainerElement.querySelector('.cdk-overlay-backdrop') as HTMLElement;

backdrop.click();
expect(spy).toHaveBeenCalledTimes(1);

viewContainerFixture.detectChanges();

viewContainerFixture.whenStable().then(() => {
// Additional clicks after the dialog has closed should not be emitted
backdrop.click();
expect(spy).toHaveBeenCalledTimes(1);
});
}));

it('should notify the observers if a dialog has been opened', () => {
dialog.afterOpen.subscribe(ref => {
expect(dialog.open(PizzaMsg, {
Expand Down

0 comments on commit df28c3d

Please sign in to comment.