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

Commit

Permalink
fix(typeahead): keep pop-up on clicking input
Browse files Browse the repository at this point in the history
Also, keep reference to event listener to unbind when scope is
destroyed. (Memory leak)
  • Loading branch information
chrisirhc authored and pkozlowski-opensource committed Aug 27, 2013
1 parent 45dd9be commit 5f9e270
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
17 changes: 17 additions & 0 deletions src/typeahead/test/typeahead.spec.js
Expand Up @@ -378,6 +378,23 @@ describe('typeahead tests', function () {
expect($scope.email).toEqual('bar@host.com');
expect(inputEl.val()).toEqual('bar@host.com');
});

it('does not close matches popup on click in input', function () {
var element = prepareInputEl("<div><input ng-model='result' typeahead='item for item in source | filter:$viewValue'></div>");
var inputEl = findInput(element);

// Note that this bug can only be found when element is in the document
$document.find('body').append(element);
// Extra teardown for this spec
this.after(function () { element.remove(); });

changeInputValueTo(element, 'b');

inputEl.click();
$scope.$digest();

expect(element).toBeOpenWithActive(2, 0);
});
});

describe('input formatting', function () {
Expand Down
15 changes: 12 additions & 3 deletions src/typeahead/typeahead.js
Expand Up @@ -243,9 +243,18 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position'])
}
});

$document.bind('click', function(){
resetMatches();
scope.$digest();
// Keep reference to click handler to unbind it.
var dismissClickHandler = function (evt) {
if (element[0] !== evt.target) {
resetMatches();
scope.$digest();
}
};

$document.bind('click', dismissClickHandler);

originalScope.$on('$destroy', function(){
$document.unbind('click', dismissClickHandler);
});

element.after($compile(popUpEl)(scope));
Expand Down

0 comments on commit 5f9e270

Please sign in to comment.