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

Commit 57f72b2

Browse files
committed
fix(dropdown): remove extra uib-keyboard-nav
Closes #4891 BREAKING CHANGE: `keyboard-nav` for the dropdown is not longer a directive and to use it you have to use `keyboard-nav` instead of `uib-keyboard-nav`.
1 parent 4dab96e commit 57f72b2

File tree

3 files changed

+9
-48
lines changed

3 files changed

+9
-48
lines changed

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>

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;
@@ -298,45 +298,6 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
298298
};
299299
})
300300

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

src/dropdown/test/dropdown.spec.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ describe('dropdownToggle', function() {
547547

548548
describe('`keyboard-nav` option', function() {
549549
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);
550+
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);
551551
}
552552
beforeEach(function() {
553553
element = dropdown();
@@ -586,7 +586,7 @@ describe('dropdownToggle', function() {
586586

587587
describe('`keyboard-nav` option', function() {
588588
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);
589+
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);
590590
}
591591
beforeEach(function() {
592592
element = dropdown();
@@ -699,7 +699,7 @@ describe('dropdownToggle', function() {
699699

700700
describe('`keyboard-nav` option with `dropdown-append-to-body` option', function() {
701701
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);
702+
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);
703703
}
704704

705705
beforeEach(function() {
@@ -709,7 +709,7 @@ describe('dropdownToggle', function() {
709709
it('should focus first list element when down arrow pressed', function() {
710710
clickDropdownToggle();
711711

712-
triggerKeyDown(element, 40);
712+
triggerKeyDown($document, 40);
713713

714714
var dropdownMenu = $document.find('#dropdown-menu');
715715

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

721721
it('should focus second list element when down arrow pressed twice', function() {
722722
clickDropdownToggle();
723-
triggerKeyDown(element, 40);
724-
triggerKeyDown(element, 40);
723+
triggerKeyDown($document, 40);
724+
triggerKeyDown($document, 40);
725725

726726
var dropdownMenu = $document.find('#dropdown-menu');
727727

0 commit comments

Comments
 (0)