File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -75,6 +75,13 @@ export class MdDialogRef<T> {
75
75
return this . _afterClosed . asObservable ( ) ;
76
76
}
77
77
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
+
78
85
/**
79
86
* Updates the dialog's position.
80
87
* @param position New dialog position.
Original file line number Diff line number Diff line change @@ -195,6 +195,29 @@ describe('MdDialog', () => {
195
195
} ) ;
196
196
} ) ) ;
197
197
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
+
198
221
it ( 'should notify the observers if a dialog has been opened' , ( ) => {
199
222
dialog . afterOpen . subscribe ( ref => {
200
223
expect ( dialog . open ( PizzaMsg , {
You can’t perform that action at this time.
0 commit comments