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> {
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.
Original file line number Diff line number Diff 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 , {
You can’t perform that action at this time.
0 commit comments