File tree 2 files changed +31
-0
lines changed 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,13 @@ export class MdDialogRef<T> {
89
89
return this . _beforeClose . asObservable ( ) ;
90
90
}
91
91
92
+ /**
93
+ * Gets an observable that emits when the overlay's backdrop has been clicked.
94
+ */
95
+ backdropClick ( ) : Observable < void > {
96
+ return this . _overlayRef . backdropClick ( ) ;
97
+ }
98
+
92
99
/**
93
100
* Updates the dialog's position.
94
101
* @param position New dialog position.
Original file line number Diff line number Diff line change @@ -237,6 +237,30 @@ describe('MdDialog', () => {
237
237
} ) ;
238
238
} ) ) ;
239
239
240
+ it ( 'should emit the backdropClick stream when clicking on the overlay backdrop' , async ( ( ) => {
241
+ const dialogRef = dialog . open ( PizzaMsg , {
242
+ viewContainerRef : testViewContainerRef
243
+ } ) ;
244
+
245
+ const spy = jasmine . createSpy ( 'backdropClick spy' ) ;
246
+ dialogRef . backdropClick ( ) . subscribe ( spy ) ;
247
+
248
+ viewContainerFixture . detectChanges ( ) ;
249
+
250
+ let backdrop = overlayContainerElement . querySelector ( '.cdk-overlay-backdrop' ) as HTMLElement ;
251
+
252
+ backdrop . click ( ) ;
253
+ expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
254
+
255
+ viewContainerFixture . detectChanges ( ) ;
256
+
257
+ viewContainerFixture . whenStable ( ) . then ( ( ) => {
258
+ // Additional clicks after the dialog has closed should not be emitted
259
+ backdrop . click ( ) ;
260
+ expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
261
+ } ) ;
262
+ } ) ) ;
263
+
240
264
it ( 'should notify the observers if a dialog has been opened' , ( ) => {
241
265
dialog . afterOpen . subscribe ( ref => {
242
266
expect ( dialog . open ( PizzaMsg , {
You can’t perform that action at this time.
0 commit comments