Skip to content
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

Merged
merged 1 commit into from
Feb 15, 2017

Conversation

crisbeto
Copy link
Member

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.

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.
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Feb 13, 2017
@crisbeto crisbeto assigned kara and mmalerba and unassigned kara Feb 13, 2017
@@ -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);
Copy link
Contributor

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?

Copy link
Member Author

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.

@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Feb 13, 2017
@andrewseguin andrewseguin merged commit a08dc55 into angular:master Feb 15, 2017
@andrewseguin andrewseguin removed the action: merge The PR is ready for merge by the caretaker label Feb 15, 2017
@abdel-ships-it
Copy link

Wouldnt it have been better to use HostListener instead?

@HostListener('document.key.Escape', ['$event']) escapeFired { this.handleEscapeKey() }

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 host over HostListener. HostListener is actually never used in the codebase. This is a perfect use case for HostListener, and I am curious on why you decided to add listeners to the document manually instead.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Closing Dialog using escape only works after initial open w/ button focused
6 participants