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

Commit 9d139a5

Browse files
committed
refactor(typeahead): change to switch
1 parent d9e3dd5 commit 9d139a5

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

Diff for: src/typeahead/typeahead.js

+22-16
Original file line numberDiff line numberDiff line change
@@ -365,23 +365,29 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap
365365

366366
evt.preventDefault();
367367

368-
if (evt.which === 40) {
369-
scope.activeIdx = (scope.activeIdx + 1) % scope.matches.length;
370-
scope.$digest();
371-
popUpEl.children()[scope.activeIdx].scrollIntoView(false);
372-
} else if (evt.which === 38) {
373-
scope.activeIdx = (scope.activeIdx > 0 ? scope.activeIdx : scope.matches.length) - 1;
374-
scope.$digest();
375-
popUpEl.children()[scope.activeIdx].scrollIntoView(false);
376-
} else if (evt.which === 13 || evt.which === 9) {
377-
scope.$apply(function () {
378-
scope.select(scope.activeIdx);
379-
});
380-
} else if (evt.which === 27) {
381-
evt.stopPropagation();
368+
switch (evt.which) {
369+
case 9:
370+
case 13:
371+
scope.$apply(function () {
372+
scope.select(scope.activeIdx);
373+
});
374+
break;
375+
case 27:
376+
evt.stopPropagation();
382377

383-
resetMatches();
384-
scope.$digest();
378+
resetMatches();
379+
scope.$digest();
380+
break;
381+
case 38:
382+
scope.activeIdx = (scope.activeIdx > 0 ? scope.activeIdx : scope.matches.length) - 1;
383+
scope.$digest();
384+
popUpEl.children()[scope.activeIdx].scrollIntoView(false);
385+
break;
386+
case 40:
387+
scope.activeIdx = (scope.activeIdx + 1) % scope.matches.length;
388+
scope.$digest();
389+
popUpEl.children()[scope.activeIdx].scrollIntoView(false);
390+
break;
385391
}
386392
});
387393

0 commit comments

Comments
 (0)