diff --git a/src/uiSelectController.js b/src/uiSelectController.js index 9fe273ac2..e0e799ecb 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -437,6 +437,11 @@ uis.controller('uiSelectCtrl', _ensureHighlightVisible(); } + if (key === KEY.ENTER || key === KEY.ESC) { + e.preventDefault(); + e.stopPropagation(); + } + }); // If tagging try to split by tokens and add items diff --git a/test/select.spec.js b/test/select.spec.js index d502040b4..11ddcb640 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -1510,6 +1510,34 @@ describe('ui-select tests', function() { }); + it('should stop the propagation when pressing ENTER key from dropdown', function() { + + var el = createUiSelectMultiple(); + var searchInput = el.find('.ui-select-search'); + spyOn(jQuery.Event.prototype, 'preventDefault'); + spyOn(jQuery.Event.prototype, 'stopPropagation'); + + triggerKeydown(searchInput, Key.Down) + triggerKeydown(searchInput, Key.Enter) + expect(jQuery.Event.prototype.preventDefault).toHaveBeenCalled(); + expect(jQuery.Event.prototype.stopPropagation).toHaveBeenCalled(); + + }); + + it('should stop the propagation when pressing ESC key from dropdown', function() { + + var el = createUiSelectMultiple(); + var searchInput = el.find('.ui-select-search'); + spyOn(jQuery.Event.prototype, 'preventDefault'); + spyOn(jQuery.Event.prototype, 'stopPropagation'); + + triggerKeydown(searchInput, Key.Down) + triggerKeydown(searchInput, Key.Escape) + expect(jQuery.Event.prototype.preventDefault).toHaveBeenCalled(); + expect(jQuery.Event.prototype.stopPropagation).toHaveBeenCalled(); + + }); + it('should increase $select.activeIndex when pressing DOWN key from dropdown', function() { var el = createUiSelectMultiple();