feat(dialog): expose backdrop clicks (#6511)

This commit is contained in:
Will Howell
2017-08-22 14:48:41 -04:00
committed by Kara
parent 6cdbf36103
commit df28c3d5ab
2 changed files with 31 additions and 0 deletions
+7
View File
@@ -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.
+24
View File
@@ -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, {