Skip to content

Commit

Permalink
fix(dropdown): fix up arrow nav support
Browse files Browse the repository at this point in the history
* add support for when user opens dropdown and then presses the up arrow key.

Fixes angular-ui#4327
  • Loading branch information
icfantv committed Sep 2, 2015
1 parent 7556bed commit f7d13bb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/dropdown/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,19 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
break;
}
case (38): { // Up
dropdownCtrl.selectedOption = dropdownCtrl.selectedOption === 0 ?
0 : dropdownCtrl.selectedOption - 1;
if (!angular.isNumber(dropdownCtrl.selectedOption)) {
dropdownCtrl.selectedOption = elems.length - 1;
} else {
dropdownCtrl.selectedOption = dropdownCtrl.selectedOption === 0 ?
0 : dropdownCtrl.selectedOption - 1;
}
break;
}
}
elems[dropdownCtrl.selectedOption].focus();
}
});
}

};
})

Expand Down
11 changes: 11 additions & 0 deletions src/dropdown/test/dropdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,17 @@ describe('dropdownToggle', function() {
expect(isFocused(focusEl)).toBe(false);
});

it('should focus last list element when up arrow pressed after dropdown toggled', function() {
$document.find('body').append(element);
clickDropdownToggle();
expect(element.hasClass(dropdownConfig.openClass)).toBe(true);

triggerKeyDown($document, 38);
var elems = element.find('ul').eq(0).find('a');
var focusEl = elems.eq(elems.length - 1);
expect(isFocused(focusEl)).toBe(true);
});

it('should not focus any list element when down arrow pressed if closed', function() {
$document.find('body').append(element);
triggerKeyDown($document, 40);
Expand Down

0 comments on commit f7d13bb

Please sign in to comment.