File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 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> {
8989 return this . _beforeClose . asObservable ( ) ;
9090 }
9191
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+
9299 /**
93100 * Updates the dialog's position.
94101 * @param position New dialog position.
Original file line number Diff line number Diff line change @@ -237,6 +237,30 @@ describe('MdDialog', () => {
237237 } ) ;
238238 } ) ) ;
239239
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+
240264 it ( 'should notify the observers if a dialog has been opened' , ( ) => {
241265 dialog . afterOpen . subscribe ( ref => {
242266 expect ( dialog . open ( PizzaMsg , {
You can’t perform that action at this time.
0 commit comments