@@ -15,7 +15,6 @@ import {
1515 ComponentRef
1616} from '@angular/core' ;
1717import { ComponentPortal , PortalInjector , TemplatePortal } from '@angular/cdk/portal' ;
18- import { ESCAPE } from '@angular/cdk/keycodes' ;
1918import { Observable } from 'rxjs/Observable' ;
2019import { Subject } from 'rxjs/Subject' ;
2120import { DialogRef } from './dialog-ref' ;
@@ -46,9 +45,6 @@ import {
4645 * Service to open modal dialogs.
4746 */
4847export class Dialog {
49- /** A the handleKeydown method bound to the class instance. */
50- private _boundKeydown = this . _handleKeydown . bind ( this ) ;
51-
5248 /** Stream that emits when all dialogs are closed. */
5349 get _afterAllClosed ( ) : Observable < void > {
5450 return this . _parentDialog ? this . _parentDialog . afterAllClosed : this . _afterAllClosedBase ;
@@ -83,10 +79,6 @@ export class Dialog {
8379 if ( ! _parentDialog && location ) {
8480 location . subscribe ( ( ) => this . closeAll ( ) ) ;
8581 }
86-
87- this . afterAllClosed . subscribe ( ( ) => {
88- document . removeEventListener ( 'keydown' , this . _boundKeydown ) ;
89- } ) ;
9082 }
9183
9284 /** Gets an open dialog by id. */
@@ -134,18 +126,16 @@ export class Dialog {
134126 }
135127
136128 /**
137- * Registers a keydown listener, and forwards emitting events for when dialogs are opened and all
138- * dialogs are closed.
129+ * Forwards emitting events for when dialogs are opened and all dialogs are closed.
139130 */
140131 private registerDialogRef ( dialogRef : DialogRef < any > ) : void {
141- if ( ! this . openDialogs . length ) {
142- document . addEventListener ( 'keydown' , this . _boundKeydown ) ;
143- }
144132 this . openDialogs . push ( dialogRef ) ;
133+
145134 let dialogOpenSub = dialogRef . afterOpen ( ) . subscribe ( ( ) => {
146135 this . afterOpen . next ( dialogRef ) ;
147136 dialogOpenSub . unsubscribe ( ) ;
148137 } ) ;
138+
149139 let dialogCloseSub = dialogRef . afterClosed ( ) . subscribe ( ( ) => {
150140 let dialogIdx = this . _openDialogs . indexOf ( dialogRef ) ;
151141 if ( dialogIdx !== - 1 ) { this . _openDialogs . splice ( dialogIdx , 1 ) ; }
@@ -157,20 +147,6 @@ export class Dialog {
157147 } ) ;
158148 }
159149
160- /**
161- * Handles global key presses while there are open dialogs. Closes the
162- * top dialog when the user presses escape.
163- */
164- private _handleKeydown ( event : KeyboardEvent ) : void {
165- const topDialog = this . openDialogs [ this . openDialogs . length - 1 ] ;
166- const canClose = topDialog ? ! topDialog . disableClose : false ;
167-
168- if ( event . keyCode === ESCAPE && canClose ) {
169- topDialog . close ( ) ;
170- }
171- }
172-
173-
174150 /**
175151 * Creates an overlay config from a dialog config.
176152 * @param config The dialog configuration.
0 commit comments