Skip to content

Commit 83c0418

Browse files
committed
Shortend the check for activeIndex.
1 parent 4d08507 commit 83c0418

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

src/uiSelectController.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -562,32 +562,25 @@ uis.controller('uiSelectCtrl',
562562

563563
function _handleDropDownSelection(key) {
564564
var processed = true;
565-
var tempIndex;
565+
var idx;
566566
switch (key) {
567567
case KEY.DOWN:
568568
if (!ctrl.open && ctrl.multiple) ctrl.activate(false, true); //In case its the search input in 'multiple' mode
569569
else if (ctrl.activeIndex < ctrl.items.length - 1) {
570-
do{
571-
tempIndex = ctrl.activeIndex + 1;
572-
if (tempIndex < ctrl.items.length)
573-
{
574-
ctrl.activeIndex = tempIndex;
575-
}
570+
idx = ++ctrl.activeIndex;
571+
while(_isItemDisabled(ctrl.items[idx]) && idx < ctrl.items.length) {
572+
ctrl.activeIndex = ++idx;
576573
}
577-
while (_isItemDisabled(ctrl.items[tempIndex]) && tempIndex < ctrl.items.length && tempIndex++);
578574
}
579575
break;
580576
case KEY.UP:
577+
var minActiveIndex = (ctrl.search.length === 0 && ctrl.tagging.isActivated) ? -1 : 0;
581578
if (!ctrl.open && ctrl.multiple) ctrl.activate(false, true); //In case its the search input in 'multiple' mode
582-
else if (ctrl.activeIndex > 0 || (ctrl.search.length === 0 && ctrl.tagging.isActivated && ctrl.activeIndex > -1)) {
583-
do{
584-
tempIndex = ctrl.activeIndex - 1;
585-
if (tempIndex >= 0)
586-
{
587-
ctrl.activeIndex = tempIndex;
588-
}
579+
else if (ctrl.activeIndex > minActiveIndex) {
580+
idx = --ctrl.activeIndex;
581+
while(_isItemDisabled(ctrl.items[idx]) && idx > minActiveIndex) {
582+
ctrl.activeIndex = --idx;
589583
}
590-
while (_isItemDisabled(ctrl.items[tempIndex]) && tempIndex >= 0 && tempIndex--);
591584
}
592585
break;
593586
case KEY.TAB:

0 commit comments

Comments
 (0)