diff --git a/src/typeahead/test/typeahead.spec.js b/src/typeahead/test/typeahead.spec.js index 0675f257a1..1c374f40fe 100644 --- a/src/typeahead/test/typeahead.spec.js +++ b/src/typeahead/test/typeahead.spec.js @@ -1,6 +1,6 @@ describe('typeahead tests', function () { - var $scope, $compile, $document; + var $scope, $compile, $document, $timeout; var changeInputValueTo; beforeEach(module('ui.bootstrap.typeahead')); @@ -18,7 +18,7 @@ describe('typeahead tests', function () { }; }); })); - beforeEach(inject(function (_$rootScope_, _$compile_, _$document_, $sniffer) { + beforeEach(inject(function (_$rootScope_, _$compile_, _$document_, _$timeout_, $sniffer) { $scope = _$rootScope_; $scope.source = ['foo', 'bar', 'baz']; $scope.states = [ @@ -27,6 +27,7 @@ describe('typeahead tests', function () { ]; $compile = _$compile_; $document = _$document_; + $timeout = _$timeout_; changeInputValueTo = function (element, value) { var inputEl = findInput(element); inputEl.val(value); @@ -396,6 +397,25 @@ describe('typeahead tests', function () { expect(inputEl.val()).toEqual('bar@host.com'); }); + it('issue 964 - should not show popup with matches if an element is not focused', function () { + + $scope.items = function(viewValue) { + return $timeout(function(){ + return [viewValue]; + }); + }; + var element = prepareInputEl("
"); + var inputEl = findInput(element); + + changeInputValueTo(element, 'match'); + $scope.$digest(); + + inputEl.blur(); + $timeout.flush(); + + expect(element).toBeClosed(); + }); + it('does not close matches popup on click in input', function () { var element = prepareInputEl(""); var inputEl = findInput(element); diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index aba06a3d73..97d67b646c 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -65,6 +65,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap //expressions used by typeahead var parserResult = typeaheadParser.parse(attrs.typeahead); + var hasFocus; //pop-up element used to display matches var popUpEl = angular.element('