From af01d52471cee8a3760f07a70376dff50712c0fa Mon Sep 17 00:00:00 2001 From: Joel Date: Tue, 21 Apr 2015 02:11:25 -0300 Subject: [PATCH 1/2] Stop propagation when pressing ENTER key from dropdown --- src/uiSelectController.js | 5 +++++ test/select.spec.js | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/uiSelectController.js b/src/uiSelectController.js index 9fe273ac2..3b09adfdb 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -437,6 +437,11 @@ uis.controller('uiSelectCtrl', _ensureHighlightVisible(); } + if (key === KEY.ENTER) { + 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..f166bd82f 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -1510,6 +1510,20 @@ 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 increase $select.activeIndex when pressing DOWN key from dropdown', function() { var el = createUiSelectMultiple(); From b19facd04fa626c0d251f0bf0345e654547f1952 Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 1 May 2015 12:29:14 -0300 Subject: [PATCH 2/2] Stop propagation when pressing ESC key from dropdown --- src/uiSelectController.js | 2 +- test/select.spec.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/uiSelectController.js b/src/uiSelectController.js index 3b09adfdb..e0e799ecb 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -437,7 +437,7 @@ uis.controller('uiSelectCtrl', _ensureHighlightVisible(); } - if (key === KEY.ENTER) { + if (key === KEY.ENTER || key === KEY.ESC) { e.preventDefault(); e.stopPropagation(); } diff --git a/test/select.spec.js b/test/select.spec.js index f166bd82f..11ddcb640 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -1524,6 +1524,20 @@ describe('ui-select tests', function() { }); + 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();