Skip to content

Commit

Permalink
fix(typeahead) should not highlight first result (for ui-bootstrap.js)
Browse files Browse the repository at this point in the history
  • Loading branch information
julesbou committed Feb 26, 2014
1 parent d4c2a65 commit ee7cc2c
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions ui-bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3145,7 +3145,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
if (inputValue === modelCtrl.$viewValue && hasFocus) {
if (matches.length > 0) {

scope.activeIdx = 0;
scope.activeIdx = -1;
scope.matches.length = 0;

//transform labels
Expand Down Expand Up @@ -3248,8 +3248,11 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
var getItemModelLabel = function (activeIdx) {
var locals = {};
var model, item;
var match = scope.matches[activeIdx];

locals[parserResult.itemName] = item = scope.matches[activeIdx].model;
if (!match) return;

locals[parserResult.itemName] = item = match.model;
model = parserResult.modelMapper(originalScope, locals);

return {
Expand All @@ -3261,8 +3264,11 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap

scope.select = function (activeIdx) {
var itemModelLabel = getItemModelLabel(activeIdx);
$setModelValue(originalScope, itemModelLabel.$model);
modelCtrl.$setValidity('editable', true);

if (itemModelLabel) {
$setModelValue(originalScope, itemModelLabel.$model);
modelCtrl.$setValidity('editable', true);
}

onSelectCallback(originalScope, itemModelLabel);

Expand All @@ -3273,7 +3279,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
};

scope.hover = function (activeIdx) {
onHoverCallback(originalScope, getItemModelLabel(activeIdx));
var itemModelLabel = getItemModelLabel(activeIdx);
itemModelLabel && onHoverCallback(originalScope, itemModelLabel);
};

scope.$watch('activeIdx', function (value) {
Expand Down Expand Up @@ -3302,6 +3309,10 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
scope.activeIdx = (scope.activeIdx ? scope.activeIdx : scope.matches.length) - 1;
scope.$digest();

if (scope.activeIdx === 0) {
scope.select(-1);
}

} else if (evt.which === 13 || evt.which === 9) {
scope.$apply(function () {
scope.select(scope.activeIdx);
Expand Down Expand Up @@ -3409,4 +3420,4 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
return function(matchItem, query) {
return query ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), '<strong>$&</strong>') : matchItem;
};
});
});

0 comments on commit ee7cc2c

Please sign in to comment.