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

Commit 0b37f08

Browse files
icfantvwesleycho
authored andcommitted
fix(dropdown): handle keyboard-nav correctly
- 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
1 parent 12c527a commit 0b37f08

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

src/dropdown/dropdown.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,9 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
278278
e.preventDefault();
279279
e.stopPropagation();
280280

281-
var elems = angular.element(element).find('a');
281+
var elems = dropdownCtrl.dropdownMenu.find('a');
282282

283-
switch (e.keyCode) {
283+
switch (e.which) {
284284
case (40): { // Down
285285
if ( !angular.isNumber(dropdownCtrl.selectedOption)) {
286286
dropdownCtrl.selectedOption = 0;

src/dropdown/test/dropdown.spec.js

+3-11
Original file line numberDiff line numberDiff line change
@@ -646,25 +646,17 @@ describe('dropdownToggle', function() {
646646
it('should focus first list element when down arrow pressed', function() {
647647
clickDropdownToggle();
648648

649-
triggerKeyDown($document, 40);
649+
triggerKeyDown(element, 40);
650650

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

656-
it('should not focus first list element when down arrow pressed if closed', function() {
657-
triggerKeyDown($document, 40);
658-
659-
expect(element.hasClass(dropdownConfig.openClass)).toBe(false);
660-
var focusEl = $document.find('ul').eq(0).find('a');
661-
expect(isFocused(focusEl)).toBe(false);
662-
});
663-
664656
it('should focus second list element when down arrow pressed twice', function() {
665657
clickDropdownToggle();
666-
triggerKeyDown($document, 40);
667-
triggerKeyDown($document, 40);
658+
triggerKeyDown(element, 40);
659+
triggerKeyDown(element, 40);
668660

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

0 commit comments

Comments
 (0)