Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 371d5a0

Browse files
codymikoljosephperrott
authored andcommitted
fix:(dialog): prevent multiple dialogs closing on esc (#11472)
1 parent 163b762 commit 371d5a0

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/components/dialog/dialog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ function MdDialogProvider($$interimElementProvider) {
964964
var parentTarget = options.parent;
965965
var keyHandlerFn = function(ev) {
966966
if (ev.keyCode === $mdConstant.KEY_CODE.ESCAPE) {
967-
ev.stopPropagation();
967+
ev.stopImmediatePropagation();
968968
ev.preventDefault();
969969

970970
smartClose();

src/components/dialog/dialog.spec.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,47 @@ describe('$mdDialog', function() {
629629
expect(container.length).toBe(0);
630630
expect(response).toBe(undefined);
631631
}));
632+
633+
it('should only remove the top most dialog on escape', inject(function($mdDialog, $timeout, $mdConstant) {
634+
635+
var root = angular.element('<div></div>');
636+
var parent = '<md-dialog class="one"></md-dialog>';
637+
var child = '<md-dialog class="two"></md-dialog>';
638+
var grandchild = '<md-dialog class="three"></md-dialog>';
639+
640+
$mdDialog.show({
641+
template: parent,
642+
multiple: true,
643+
parent: root,
644+
});
645+
runAnimation();
646+
647+
$mdDialog.show({
648+
template: child,
649+
multiple: true,
650+
parent: root[0].querySelector('md-dialog.one'),
651+
});
652+
runAnimation();
653+
654+
$mdDialog.show({
655+
template: grandchild,
656+
multiple: true,
657+
parent: root[0].querySelector('md-dialog.two'),
658+
});
659+
runAnimation();
660+
661+
root.triggerHandler({
662+
type: 'keydown',
663+
keyCode: $mdConstant.KEY_CODE.ESCAPE
664+
});
665+
runAnimation();
666+
667+
expect(root[0].querySelectorAll('md-dialog.one').length).toBe(1);
668+
expect(root[0].querySelectorAll('md-dialog.two').length).toBe(1);
669+
expect(root[0].querySelectorAll('md-dialog.three').length).toBe(0);
670+
671+
}));
672+
632673
});
633674

634675
describe('#prompt()', function() {

0 commit comments

Comments
 (0)