Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit c2e5b28

Browse files
MikeMatuszchrisirhc
authored andcommitted
fix(datepicker): don't stop ESC propagation unless dropdown is open
In reference to issue #3096 If the escape key should have other functionality in the context of a form (for example, if datepicker is on a modal) it makes sense to prevent this from happening if escape is used to close the dropdown. If the dropdown is closed, however, the event should be allowed to propagate. Fixes #3096 Closes #3179
1 parent 2724b46 commit c2e5b28

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

Diff for: src/datepicker/datepicker.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,9 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
571571
scope.keydown = function(evt) {
572572
if (evt.which === 27) {
573573
evt.preventDefault();
574-
evt.stopPropagation();
574+
if (scope.isOpen) {
575+
evt.stopPropagation();
576+
}
575577
scope.close();
576578
} else if (evt.which === 40 && !scope.isOpen) {
577579
scope.isOpen = true;

Diff for: src/datepicker/test/datepicker.spec.js

+21
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,27 @@ describe('datepicker directive', function () {
12481248
expect(dropdownEl).toBeHidden();
12491249
expect(document.activeElement.tagName).toBe('INPUT');
12501250
});
1251+
1252+
it('stops the ESC key from propagating if the dropdown is open, but not when closed', function() {
1253+
expect(dropdownEl).not.toBeHidden();
1254+
1255+
dropdownEl.find('button').eq(0).focus();
1256+
expect(document.activeElement.tagName).toBe('BUTTON');
1257+
1258+
var documentKey = -1;
1259+
var getKey = function(evt) { documentKey = evt.which; };
1260+
$document.bind('keydown', getKey);
1261+
1262+
triggerKeyDown(inputEl, 'esc');
1263+
$rootScope.$digest();
1264+
expect(dropdownEl).toBeHidden();
1265+
expect(documentKey).toBe(-1);
1266+
1267+
triggerKeyDown(inputEl, 'esc');
1268+
expect(documentKey).toBe(27);
1269+
1270+
$document.unbind('keydown', getKey);
1271+
});
12511272
});
12521273
});
12531274

0 commit comments

Comments
 (0)