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

Commit cab0945

Browse files
chenyuzhcywesleycho
authored andcommitted
fix(typeahead): fix programmatic focus issue
- Fix issue where programmatic focus on typeahead input does not work Closes #5150 Fixes #764
1 parent ff5e720 commit cab0945

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/typeahead/test/typeahead.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,7 @@ describe('typeahead tests', function() {
13371337
var element = prepareInputEl('<div><input ng-model="result" uib-typeahead="item for item in source | filter:$viewValue" typeahead-min-length="0"></div>');
13381338
var inputEl = findInput(element);
13391339
inputEl.focus();
1340+
$timeout.flush();
13401341
$scope.$digest();
13411342
expect(element).toBeOpenWithActive(3, 0);
13421343
});

src/typeahead/typeahead.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,9 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap
407407
element.bind('focus', function () {
408408
hasFocus = true;
409409
if (minLength === 0 && !modelCtrl.$viewValue) {
410-
getMatchesAsync(modelCtrl.$viewValue);
410+
$timeout(function() {
411+
getMatchesAsync(modelCtrl.$viewValue);
412+
}, 0);
411413
}
412414
});
413415

0 commit comments

Comments
 (0)