From 02b4df94cb440b450c38fafebdd4aa1da463abe4 Mon Sep 17 00:00:00 2001 From: Adrien Siami Date: Mon, 12 Oct 2015 11:45:27 +0200 Subject: [PATCH] Stop propagation when selecting an entry --- src/typeahead/typeahead.js | 5 ++++- test/typeahead/typeahead_spec.js | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index f84078e611..e463f582e2 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -162,7 +162,10 @@ var Typeahead = (function() { var $selectable; if ($selectable = this.menu.getActiveSelectable()) { - this.select($selectable) && $e.preventDefault(); + if (this.select($selectable)) { + $e.preventDefault(); + $e.stopPropagation(); + } } }, diff --git a/test/typeahead/typeahead_spec.js b/test/typeahead/typeahead_spec.js index 589cf51c26..6f08b0a5aa 100644 --- a/test/typeahead/typeahead_spec.js +++ b/test/typeahead/typeahead_spec.js @@ -284,7 +284,7 @@ describe('Typeahead', function() { beforeEach(function() { eventName = 'enterKeyed'; - payload = jasmine.createSpyObj('event', ['preventDefault']); + payload = jasmine.createSpyObj('event', ['preventDefault', 'stopPropagation']); }); describe('when idle', function() { @@ -330,7 +330,7 @@ describe('Typeahead', function() { expect(this.view.select).toHaveBeenCalledWith($el); }); - it('should prevent default if active selectale ', function() { + it('should prevent default and stop propagation if active selectable ', function() { var $el; $el = $(''); @@ -340,6 +340,7 @@ describe('Typeahead', function() { this.input.trigger(eventName, payload); expect(payload.preventDefault).toHaveBeenCalled(); + expect(payload.stopPropagation).toHaveBeenCalled(); }); it('should not select selectable if there is no active one', function() {