-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dialog: Before handling escape key presses, check if the default acti…
…on has been prevented. Fixes #6966 - Pressing ESC on dialog when 2 dialogs are open closes both dialogs.
- Loading branch information
1 parent
3a0ec39
commit f999668
Showing
2 changed files
with
27 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f999668
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.
Is this tested on 3 dialogs? I think when you hit ESC on the top dialog, then ESC again it may close the lowest dialog (should close the middle dialog the second time.)
f999668
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.
You think or you know? If there's a bug, please provide a reduced test case.
f999668
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.
Sorry, I'm on the clock with something else and ran into the problem. I'll try to build a test case in a bit.
(Edit*: I guess I figured it was trivial simple for devs that have used these test cases to throw in a third dialog and test, but I've never used jQuery unit tests, so I wasn't sure how to set them up is there a test runner or docs for testing? I guess I can search around a bit afterwards.)
f999668
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.
Okay, so I just grabbed the test case, and added a third dialog.
http://jsfiddle.net/e4bxu/
You'll notice if you press "Escape" it will close dialog 3, but then if you immediately press "Escape" again, it will close the first dialog in the background, and leave the middle dialog (2) open.
f999668
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've found the problem, this is only triggered if the escape key is triggered through the overlay, we only bind 1 keydown handler for all overlays, and we only do it on the first overlay, and it only holds a reference to the first dialog that gets registered because it's inside a
if ( this.instances.length === 0 ) {
. There's multiple ways to fix this. But the least invasive would be to move the key binder outside of the if statement, and then put in some code to make certain that the highest overlay instance is always the one that gets triggered. It's a little icky because we leave behind all the key binders until all the overlays are gone. I'll be updating my pull request with new tests and the fix shortly.