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

Commit

Permalink
fix(dropdown): handle keyboard-nav correctly
Browse files Browse the repository at this point in the history
- fix bug in directive whereby list item selector is not being initiated on
  correct DOM element.
- fix bug in directive whereby invalid `keyCode` property of jQuery Event
  object is being referenced instead of `which`.
- update functional test to trigger keydown event on correct DOM element
  because otherwise the keydown handler in the directive is not getting
  executed.
- remove invalid functional test because it is not possible to trigger a
  keydown event on a hidden DOM element through normal UI interaction.

Closes #4110
Fixes #4091
  • Loading branch information
icfantv authored and wesleycho committed Aug 5, 2015
1 parent 12c527a commit 0b37f08
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/dropdown/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
e.preventDefault();
e.stopPropagation();

var elems = angular.element(element).find('a');
var elems = dropdownCtrl.dropdownMenu.find('a');

switch (e.keyCode) {
switch (e.which) {
case (40): { // Down
if ( !angular.isNumber(dropdownCtrl.selectedOption)) {
dropdownCtrl.selectedOption = 0;
Expand Down
14 changes: 3 additions & 11 deletions src/dropdown/test/dropdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,25 +646,17 @@ describe('dropdownToggle', function() {
it('should focus first list element when down arrow pressed', function() {
clickDropdownToggle();

triggerKeyDown($document, 40);
triggerKeyDown(element, 40);

expect(element.hasClass(dropdownConfig.openClass)).toBe(true);
var focusEl = $document.find('ul').eq(0).find('a');
expect(isFocused(focusEl)).toBe(true);
});

it('should not focus first list element when down arrow pressed if closed', function() {
triggerKeyDown($document, 40);

expect(element.hasClass(dropdownConfig.openClass)).toBe(false);
var focusEl = $document.find('ul').eq(0).find('a');
expect(isFocused(focusEl)).toBe(false);
});

it('should focus second list element when down arrow pressed twice', function() {
clickDropdownToggle();
triggerKeyDown($document, 40);
triggerKeyDown($document, 40);
triggerKeyDown(element, 40);
triggerKeyDown(element, 40);

expect(element.hasClass(dropdownConfig.openClass)).toBe(true);
var elem1 = $document.find('ul');
Expand Down

0 comments on commit 0b37f08

Please sign in to comment.