-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(dialog): escape key not working once element loses focus #3082
fix(dialog): escape key not working once element loses focus #3082
Conversation
Fixes issue in the dialog that prevented the user from being able to close via the escape key, if any of the elements inside the dialog loses focus. Fixes angular#3009.
@@ -65,6 +67,10 @@ export class MdDialog { | |||
let dialogRef = | |||
this._attachDialogContent(componentOrTemplateRef, dialogContainer, overlayRef, config); | |||
|
|||
if (!this._openDialogs.length && !this._parentDialog) { | |||
document.addEventListener('keydown', this._boundKeydown); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we don't have access to a Renerer we can use to do this at this point in the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't. Angular only injects the renderer in components.
Wouldnt it have been better to use HostListener instead?
This would attach a listener on the document rather than the element, thus preventing this bug. I am unsure why the MD team prefers the use of |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Fixes issue in the dialog that prevented the user from being able to close via the escape key, if any of the elements inside the dialog loses focus.
Fixes #3009.