Skip to content

Commit 2d9cba4

Browse files
committed
feat(dialog): expose backdrop clicks
1 parent 72360e2 commit 2d9cba4

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/lib/dialog/dialog-ref.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ export class MdDialogRef<T> {
7575
return this._afterClosed.asObservable();
7676
}
7777

78+
/**
79+
* Gets an observable that emits when the overlay's backdrop has been clicked.
80+
*/
81+
backdropClick(): Observable<void> {
82+
return this._overlayRef.backdropClick();
83+
}
84+
7885
/**
7986
* Updates the dialog's position.
8087
* @param position New dialog position.

src/lib/dialog/dialog.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,29 @@ describe('MdDialog', () => {
195195
});
196196
}));
197197

198+
it('should emit the backdropClick stream when clicking on the overlay backdrop', async(() => {
199+
const dialogRef = dialog.open(PizzaMsg, {
200+
viewContainerRef: testViewContainerRef
201+
});
202+
203+
const spy = jasmine.createSpy('backdropClick spy');
204+
dialogRef.backdropClick().subscribe(spy);
205+
206+
viewContainerFixture.detectChanges();
207+
208+
let backdrop = overlayContainerElement.querySelector('.cdk-overlay-backdrop') as HTMLElement;
209+
210+
backdrop.click();
211+
expect(spy).toHaveBeenCalledTimes(1);
212+
213+
viewContainerFixture.detectChanges();
214+
215+
viewContainerFixture.whenStable().then(() => {
216+
backdrop.click();
217+
expect(spy).toHaveBeenCalledTimes(1);
218+
});
219+
}));
220+
198221
it('should notify the observers if a dialog has been opened', () => {
199222
dialog.afterOpen.subscribe(ref => {
200223
expect(dialog.open(PizzaMsg, {

0 commit comments

Comments
 (0)