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

Commit 5f91e77

Browse files
author
Brian Feister
committed
Merge pull request #901 from loverajoel/joel_stop_propagation_enter_esc
Stop propagation when pressing ENTER or ESC key from dropdown
2 parents 948d383 + b19facd commit 5f91e77

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/uiSelectController.js

+5
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,11 @@ uis.controller('uiSelectCtrl',
437437
_ensureHighlightVisible();
438438
}
439439

440+
if (key === KEY.ENTER || key === KEY.ESC) {
441+
e.preventDefault();
442+
e.stopPropagation();
443+
}
444+
440445
});
441446

442447
// If tagging try to split by tokens and add items

test/select.spec.js

+28
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,34 @@ describe('ui-select tests', function() {
15101510

15111511
});
15121512

1513+
it('should stop the propagation when pressing ENTER key from dropdown', function() {
1514+
1515+
var el = createUiSelectMultiple();
1516+
var searchInput = el.find('.ui-select-search');
1517+
spyOn(jQuery.Event.prototype, 'preventDefault');
1518+
spyOn(jQuery.Event.prototype, 'stopPropagation');
1519+
1520+
triggerKeydown(searchInput, Key.Down)
1521+
triggerKeydown(searchInput, Key.Enter)
1522+
expect(jQuery.Event.prototype.preventDefault).toHaveBeenCalled();
1523+
expect(jQuery.Event.prototype.stopPropagation).toHaveBeenCalled();
1524+
1525+
});
1526+
1527+
it('should stop the propagation when pressing ESC key from dropdown', function() {
1528+
1529+
var el = createUiSelectMultiple();
1530+
var searchInput = el.find('.ui-select-search');
1531+
spyOn(jQuery.Event.prototype, 'preventDefault');
1532+
spyOn(jQuery.Event.prototype, 'stopPropagation');
1533+
1534+
triggerKeydown(searchInput, Key.Down)
1535+
triggerKeydown(searchInput, Key.Escape)
1536+
expect(jQuery.Event.prototype.preventDefault).toHaveBeenCalled();
1537+
expect(jQuery.Event.prototype.stopPropagation).toHaveBeenCalled();
1538+
1539+
});
1540+
15131541
it('should increase $select.activeIndex when pressing DOWN key from dropdown', function() {
15141542

15151543
var el = createUiSelectMultiple();

0 commit comments

Comments
 (0)