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

Commit 36a7250

Browse files
committed
fix(dropdown): remove extra uib-keyboard-nav
1 parent 85fdfc2 commit 36a7250

File tree

3 files changed

+15
-48
lines changed

3 files changed

+15
-48
lines changed

Diff for: src/dropdown/docs/demo.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373

7474
<hr>
7575
<!-- Single button with keyboard nav -->
76-
<div class="btn-group" uib-dropdown uib-keyboard-nav>
76+
<div class="btn-group" uib-dropdown keyboard-nav>
7777
<button id="simple-btn-keyboard-nav" type="button" class="btn btn-primary" uib-dropdown-toggle>
7878
Dropdown with keyboard navigation <span class="caret"></span>
7979
</button>
@@ -92,7 +92,7 @@ <h4>append-to vs. append-to-body vs. inline example</h4>
9292
<div id="dropdown-scrollable-container" style="height: 15em; overflow: auto;">
9393
<div id="dropdown-long-content">
9494
<div id="dropdown-hidden-container">
95-
<div class="btn-group" uib-dropdown dropdown-append-to="appendToEl">
95+
<div class="btn-group" uib-dropdown keyboard-nav dropdown-append-to="appendToEl">
9696
<button id="btn-append-to" type="button" class="btn btn-primary" uib-dropdown-toggle>
9797
Dropdown in Container <span class="caret"></span>
9898
</button>

Diff for: src/dropdown/dropdown.js

+1-40
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
101101
}
102102

103103
appendToBody = angular.isDefined($attrs.dropdownAppendToBody);
104-
keynavEnabled = angular.isDefined($attrs.uibKeyboardNav);
104+
keynavEnabled = angular.isDefined($attrs.keyboardNav);
105105

106106
if (appendToBody && !appendTo) {
107107
appendTo = body;
@@ -303,45 +303,6 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
303303
};
304304
})
305305

306-
.directive('uibKeyboardNav', function() {
307-
return {
308-
restrict: 'A',
309-
require: '?^uibDropdown',
310-
link: function(scope, element, attrs, dropdownCtrl) {
311-
element.bind('keydown', function(e) {
312-
if ([38, 40].indexOf(e.which) !== -1) {
313-
e.preventDefault();
314-
e.stopPropagation();
315-
316-
var elems = dropdownCtrl.dropdownMenu.find('a');
317-
318-
switch (e.which) {
319-
case 40: { // Down
320-
if (!angular.isNumber(dropdownCtrl.selectedOption)) {
321-
dropdownCtrl.selectedOption = 0;
322-
} else {
323-
dropdownCtrl.selectedOption = dropdownCtrl.selectedOption === elems.length - 1 ?
324-
dropdownCtrl.selectedOption : dropdownCtrl.selectedOption + 1;
325-
}
326-
break;
327-
}
328-
case 38: { // Up
329-
if (!angular.isNumber(dropdownCtrl.selectedOption)) {
330-
dropdownCtrl.selectedOption = elems.length - 1;
331-
} else {
332-
dropdownCtrl.selectedOption = dropdownCtrl.selectedOption === 0 ?
333-
0 : dropdownCtrl.selectedOption - 1;
334-
}
335-
break;
336-
}
337-
}
338-
elems[dropdownCtrl.selectedOption].focus();
339-
}
340-
});
341-
}
342-
};
343-
})
344-
345306
.directive('uibDropdownToggle', function() {
346307
return {
347308
require: '?^uibDropdown',

Diff for: src/dropdown/test/dropdown.spec.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ describe('dropdownToggle', function() {
3030
element.trigger(e);
3131
};
3232

33+
var triggerDocumentKeyDown = function (element, keyCode) {
34+
var e = $.Event('keydown');
35+
e.which = keyCode;
36+
$document.trigger(e);
37+
};
38+
3339
var isFocused = function(elm) {
3440
return elm[0] === document.activeElement;
3541
};
@@ -547,7 +553,7 @@ describe('dropdownToggle', function() {
547553

548554
describe('`keyboard-nav` option', function() {
549555
function dropdown() {
550-
return $compile('<li uib-dropdown uib-keyboard-nav><a href uib-dropdown-toggle></a><ul><li><a href>Hello</a></li><li><a href>Hello Again</a></li></ul></li>')($rootScope);
556+
return $compile('<li uib-dropdown keyboard-nav><a href uib-dropdown-toggle></a><ul><li><a href>Hello</a></li><li><a href>Hello Again</a></li></ul></li>')($rootScope);
551557
}
552558
beforeEach(function() {
553559
element = dropdown();
@@ -586,7 +592,7 @@ describe('dropdownToggle', function() {
586592

587593
describe('`keyboard-nav` option', function() {
588594
function dropdown() {
589-
return $compile('<li uib-dropdown uib-keyboard-nav><a href uib-dropdown-toggle></a><ul><li><a href>Hello</a></li><li><a href>Hello Again</a></li></ul></li>')($rootScope);
595+
return $compile('<li uib-dropdown keyboard-nav><a href uib-dropdown-toggle></a><ul><li><a href>Hello</a></li><li><a href>Hello Again</a></li></ul></li>')($rootScope);
590596
}
591597
beforeEach(function() {
592598
element = dropdown();
@@ -699,7 +705,7 @@ describe('dropdownToggle', function() {
699705

700706
describe('`keyboard-nav` option with `dropdown-append-to-body` option', function() {
701707
function dropdown() {
702-
return $compile('<li uib-dropdown dropdown-append-to-body uib-keyboard-nav><a href uib-dropdown-toggle></a><ul class="uib-dropdown-menu" id="dropdown-menu"><li><a href>Hello On Body</a></li><li><a href>Hello Again</a></li></ul></li>')($rootScope);
708+
return $compile('<li uib-dropdown dropdown-append-to-body keyboard-nav><a href uib-dropdown-toggle></a><ul class="uib-dropdown-menu" id="dropdown-menu"><li><a href>Hello On Body</a></li><li><a href>Hello Again</a></li></ul></li>')($rootScope);
703709
}
704710

705711
beforeEach(function() {
@@ -709,7 +715,7 @@ describe('dropdownToggle', function() {
709715
it('should focus first list element when down arrow pressed', function() {
710716
clickDropdownToggle();
711717

712-
triggerKeyDown(element, 40);
718+
triggerDocumentKeyDown(element, 40);
713719

714720
var dropdownMenu = $document.find('#dropdown-menu');
715721

@@ -720,8 +726,8 @@ describe('dropdownToggle', function() {
720726

721727
it('should focus second list element when down arrow pressed twice', function() {
722728
clickDropdownToggle();
723-
triggerKeyDown(element, 40);
724-
triggerKeyDown(element, 40);
729+
triggerDocumentKeyDown(element, 40);
730+
triggerDocumentKeyDown(element, 40);
725731

726732
var dropdownMenu = $document.find('#dropdown-menu');
727733

0 commit comments

Comments
 (0)