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

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.

Closes #4330
Fixes #4327
  • Loading branch information
icfantv authored and wesleycho committed Sep 2, 2015
1 parent c7d669f commit defcbbb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/dropdown/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
}
case (38): {
if (!angular.isNumber(self.selectedOption)) {
return;
self.selectedOption = elems.length - 1;
} else {
self.selectedOption = self.selectedOption === 0 ?
0 : self.selectedOption - 1;
Expand Down 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
10 changes: 10 additions & 0 deletions src/dropdown/test/dropdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,16 @@ 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();
triggerKeyDown($document, 38);

expect(element.hasClass(dropdownConfig.openClass)).toBe(true);
var focusEl = element.find('ul').eq(0).find('a').eq(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 defcbbb

Please sign in to comment.