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

Commit

Permalink
refactor(typeahead): change to switch
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleycho committed Nov 30, 2015
1 parent d9e3dd5 commit 9d139a5
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,23 +365,29 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap

evt.preventDefault();

if (evt.which === 40) {
scope.activeIdx = (scope.activeIdx + 1) % scope.matches.length;
scope.$digest();
popUpEl.children()[scope.activeIdx].scrollIntoView(false);
} else if (evt.which === 38) {
scope.activeIdx = (scope.activeIdx > 0 ? scope.activeIdx : scope.matches.length) - 1;
scope.$digest();
popUpEl.children()[scope.activeIdx].scrollIntoView(false);
} else if (evt.which === 13 || evt.which === 9) {
scope.$apply(function () {
scope.select(scope.activeIdx);
});
} else if (evt.which === 27) {
evt.stopPropagation();
switch (evt.which) {
case 9:
case 13:
scope.$apply(function () {
scope.select(scope.activeIdx);
});
break;
case 27:
evt.stopPropagation();

resetMatches();
scope.$digest();
resetMatches();
scope.$digest();
break;
case 38:
scope.activeIdx = (scope.activeIdx > 0 ? scope.activeIdx : scope.matches.length) - 1;
scope.$digest();
popUpEl.children()[scope.activeIdx].scrollIntoView(false);
break;
case 40:
scope.activeIdx = (scope.activeIdx + 1) % scope.matches.length;
scope.$digest();
popUpEl.children()[scope.activeIdx].scrollIntoView(false);
break;
}
});

Expand Down

0 comments on commit 9d139a5

Please sign in to comment.