diff --git a/src/dropdown/dropdown.js b/src/dropdown/dropdown.js index ab698579de..8f1a80f416 100644 --- a/src/dropdown/dropdown.js +++ b/src/dropdown/dropdown.js @@ -292,8 +292,12 @@ 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; } } @@ -301,7 +305,6 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position']) } }); } - }; }) diff --git a/src/dropdown/test/dropdown.spec.js b/src/dropdown/test/dropdown.spec.js index 31c92b355a..aafb14488e 100644 --- a/src/dropdown/test/dropdown.spec.js +++ b/src/dropdown/test/dropdown.spec.js @@ -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);