Skip to content

Commit d1a3ae1

Browse files
committed
Merge pull request #210 from diogotrentini/master
Fix Typeahead focus out
2 parents d75b0ea + 5e621b7 commit d1a3ae1

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/typeahead/test/typeahead.spec.js

+39
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,45 @@ describe('typeahead tests', function () {
528528
expect($scope.isLoading).toBeFalsy();
529529
});
530530

531+
it('should update loading callback when input loses focus', function() {
532+
$scope.isLoading = false;
533+
$scope.items = function(viewValue) {
534+
return $timeout(function() {
535+
return [viewValue];
536+
});
537+
};
538+
539+
var element = prepareInputEl("<div><input ng-model='result' typeahead='item for item in items($viewValue)' typeahead-loading='isLoading'></div>");
540+
changeInputValueTo(element, 'foo');
541+
542+
expect($scope.isLoading).toBeTruthy();
543+
544+
findInput(element).blur();
545+
$timeout.flush();
546+
547+
expect($scope.isLoading).toBeFalsy();
548+
});
549+
550+
it('should update loading callback when promise is rejected', inject(function($q) {
551+
var element, deferred;
552+
553+
deferred = $q.defer();
554+
$scope.isLoading = false;
555+
$scope.items = function(viewValue) {
556+
return deferred.promise;
557+
};
558+
559+
element = prepareInputEl("<div><input ng-model='result' typeahead='item for item in items($viewValue)' typeahead-loading='isLoading'></div>");
560+
changeInputValueTo(element, 'foo');
561+
562+
expect($scope.isLoading).toBeTruthy();
563+
564+
deferred.reject(['bar']);
565+
$timeout.flush();
566+
567+
expect($scope.isLoading).toBeFalsy();
568+
}));
569+
531570
it('does not close matches popup on click in input', function () {
532571
var element = prepareInputEl("<div><input ng-model='result' typeahead='item for item in source | filter:$viewValue'></div>");
533572
var inputEl = findInput(element);

src/typeahead/typeahead.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ angular.module('mm.foundation.typeahead', ['mm.foundation.position', 'mm.foundat
128128
} else {
129129
resetMatches();
130130
}
131-
isLoadingSetter(originalScope, false);
132131
}
133132
}, function(){
134133
resetMatches();
134+
}).finally(function() {
135135
isLoadingSetter(originalScope, false);
136136
});
137137
};

0 commit comments

Comments
 (0)