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

Commit

Permalink
fix(typeahead): incompatibility with ng-focus
Browse files Browse the repository at this point in the history
Used timeout to avoid $rootScope:inprog error

Fixes #1773
Closes #1793
  • Loading branch information
shayanelhami authored and chrisirhc committed Mar 17, 2014
1 parent f9aa459 commit d002493
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/typeahead/test/typeahead.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,23 @@ describe('typeahead tests', function () {

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

it('issue #1773 - should not trigger an error when used with ng-focus', function () {

var element = prepareInputEl('<div><input ng-model="result" typeahead="item for item in source | filter:$viewValue" ng-focus="foo()"></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');
var match = $(findMatches(element)[1]).find('a')[0];

$(match).click();
$scope.$digest();
});
});

describe('input formatting', function () {
Expand Down
3 changes: 2 additions & 1 deletion src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
resetMatches();

//return focus to the input element if a mach was selected via a mouse click event
element[0].focus();
// use timeout to avoid $rootScope:inprog error
$timeout(function() { element[0].focus(); }, 0, false);
};

//bind keyboard events: arrows up(38) / down(40), enter(13) and tab(9), esc(27)
Expand Down

0 comments on commit d002493

Please sign in to comment.