Skip to content

Commit 35e2096

Browse files
authored
Merge pull request #13 from Intrepidd/enter-key-stop-propagation
Stop propagation when selecting an entry
2 parents 4de8558 + 02b4df9 commit 35e2096

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/typeahead/typeahead.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,10 @@ var Typeahead = (function() {
162162
var $selectable;
163163

164164
if ($selectable = this.menu.getActiveSelectable()) {
165-
this.select($selectable) && $e.preventDefault();
165+
if (this.select($selectable)) {
166+
$e.preventDefault();
167+
$e.stopPropagation();
168+
}
166169
}
167170
},
168171

test/typeahead/typeahead_spec.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ describe('Typeahead', function() {
284284

285285
beforeEach(function() {
286286
eventName = 'enterKeyed';
287-
payload = jasmine.createSpyObj('event', ['preventDefault']);
287+
payload = jasmine.createSpyObj('event', ['preventDefault', 'stopPropagation']);
288288
});
289289

290290
describe('when idle', function() {
@@ -330,7 +330,7 @@ describe('Typeahead', function() {
330330
expect(this.view.select).toHaveBeenCalledWith($el);
331331
});
332332

333-
it('should prevent default if active selectale ', function() {
333+
it('should prevent default and stop propagation if active selectable ', function() {
334334
var $el;
335335

336336
$el = $('<bah>');
@@ -340,6 +340,7 @@ describe('Typeahead', function() {
340340
this.input.trigger(eventName, payload);
341341

342342
expect(payload.preventDefault).toHaveBeenCalled();
343+
expect(payload.stopPropagation).toHaveBeenCalled();
343344
});
344345

345346
it('should not select selectable if there is no active one', function() {

0 commit comments

Comments
 (0)