From 56217fad27ac19f9727e87ea1725810e664e8bd8 Mon Sep 17 00:00:00 2001 From: jlukic Date: Wed, 21 Jan 2015 13:47:13 -0500 Subject: [PATCH] Fixes keyboard nav when active item is in hidden menu --- src/definitions/modules/dropdown.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/definitions/modules/dropdown.js b/src/definitions/modules/dropdown.js index 342889b1a..bb427c90f 100644 --- a/src/definitions/modules/dropdown.js +++ b/src/definitions/modules/dropdown.js @@ -469,7 +469,7 @@ $.fn.dropdown = function(parameters) { keydown: function(event) { var $currentlySelected = $item.not(className.filtered).filter('.' + className.selected).eq(0), - $activeItem = $item.filter('.' + className.active).eq(0), + $activeItem = $menu.children('.' + className.active).eq(0), $selectedItem = ($currentlySelected.length > 0) ? $currentlySelected : $activeItem, @@ -479,6 +479,7 @@ $.fn.dropdown = function(parameters) { $subMenu = $selectedItem.children(selector.menu), $parentMenu = $selectedItem.closest(selector.menu), isSubMenuItem = $parentMenu[0] !== $menu[0], + inVisibleMenu = $parentMenu.is(':visible'), pressedKey = event.which, keys = { enter : 13, @@ -539,9 +540,9 @@ $.fn.dropdown = function(parameters) { } // up arrow (traverse menu up) if(pressedKey == keys.upArrow) { - $nextItem = (hasSelectedItem) + $nextItem = (hasSelectedItem && inVisibleMenu) ? $selectedItem.prevAll(selector.item + ':not(.' + className.filtered + ')').eq(0) - : $visibleItems.eq(0) + : $item.eq(0) ; if($visibleItems.index( $nextItem ) < 0) { module.verbose('Up key pressed but reached top of current menu'); @@ -561,9 +562,9 @@ $.fn.dropdown = function(parameters) { } // down arrow (traverse menu down) if(pressedKey == keys.downArrow) { - $nextItem = (hasSelectedItem) + $nextItem = (hasSelectedItem && inVisibleMenu) ? $nextItem = $selectedItem.nextAll(selector.item + ':not(.' + className.filtered + ')').eq(0) - : $visibleItems.eq(0) + : $item.eq(0) ; if($nextItem.length === 0) { module.verbose('Down key pressed but reached bottom of current menu');