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

Stop propagation when pressing ENTER or ESC key from dropdown #901

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/uiSelectController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down