From 8d970958ad881f12c70f9554dff52b134dc9b5fb Mon Sep 17 00:00:00 2001 From: Johann-S Date: Thu, 2 Nov 2017 10:29:11 +0100 Subject: [PATCH] Fix keyboard navigation --- js/src/dropdown.js | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/js/src/dropdown.js b/js/src/dropdown.js index 52fdf3d29fad..a9c60ea5733d 100644 --- a/js/src/dropdown.js +++ b/js/src/dropdown.js @@ -54,11 +54,13 @@ const Dropdown = (($) => { } const Selector = { - DATA_TOGGLE : '[data-toggle="dropdown"]', - FORM_CHILD : '.dropdown form', - MENU : '.dropdown-menu', - NAVBAR_NAV : '.navbar-nav', - VISIBLE_ITEMS : '.dropdown-menu .dropdown-item:not(.disabled)' + DATA_TOGGLE : '[data-toggle="dropdown"]', + FORM_CHILD : '.dropdown form', + MENU : '.dropdown-menu', + NAVBAR_NAV : '.navbar-nav', + VISIBLE_ITEMS : '.dropdown-menu .dropdown-item:not(.disabled)', + ACTIVE_ITEMS : '.dropdown-item:not(.disabled)', + DROPDOWN_SHOWN : `.${ClassName.SHOW}:not(.dropdown-menu)` } const AttachmentMap = { @@ -414,7 +416,14 @@ const Dropdown = (($) => { return } - const parent = Dropdown._getParentFromElement(this) + let parent = Dropdown._getParentFromElement(this) + let dropdown = $(parent).children(Selector.DATA_TOGGLE)[0] + if (typeof dropdown === 'undefined') { + parent = $(parent).find(Selector.DROPDOWN_SHOWN)[0] + if (typeof parent !== 'undefined') { + dropdown = $(parent).children(Selector.DATA_TOGGLE)[0] + } + } const isActive = $(parent).hasClass(ClassName.SHOW) if (!isActive && (event.which !== ESCAPE_KEYCODE || event.which !== SPACE_KEYCODE) || @@ -429,7 +438,13 @@ const Dropdown = (($) => { return } - const items = $(parent).find(Selector.VISIBLE_ITEMS).get() + const context = $(dropdown).data(DATA_KEY) + let items = null + if (context._config.container && Util.isElement(context._config.container)) { + items = $(context._menu).find(Selector.ACTIVE_ITEMS).get() + } else { + items = $(parent).find(Selector.VISIBLE_ITEMS).get() + } if (!items.length) { return