Skip to content

Commit 6a9e8ad

Browse files
committed
Fix keyboard navigation
1 parent 712c986 commit 6a9e8ad

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

js/src/dropdown.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,15 @@ const Dropdown = (($) => {
5353
MENULEFT : 'dropdown-menu-left'
5454
}
5555

56+
// DROPDOWN_SHOWN exclude our other plugins which use .show class
5657
const Selector = {
57-
DATA_TOGGLE : '[data-toggle="dropdown"]',
58-
FORM_CHILD : '.dropdown form',
59-
MENU : '.dropdown-menu',
60-
NAVBAR_NAV : '.navbar-nav',
61-
VISIBLE_ITEMS : '.dropdown-menu .dropdown-item:not(.disabled)'
58+
DATA_TOGGLE : '[data-toggle="dropdown"]',
59+
FORM_CHILD : '.dropdown form',
60+
MENU : '.dropdown-menu',
61+
NAVBAR_NAV : '.navbar-nav',
62+
VISIBLE_ITEMS : `.dropdown-menu .dropdown-item:not(.${ClassName.DISABLED})`,
63+
ACTIVE_ITEMS : `.dropdown-item:not(.${ClassName.DISABLED})`,
64+
DROPDOWN_SHOWN : `.${ClassName.SHOW}:not(.dropdown-menu):not(.alert):not(.collapse):not(.modal):not(.popover):not(.tab-pane):not(.tooltip)`
6265
}
6366

6467
const AttachmentMap = {
@@ -414,7 +417,14 @@ const Dropdown = (($) => {
414417
return
415418
}
416419

417-
const parent = Dropdown._getParentFromElement(this)
420+
let parent = Dropdown._getParentFromElement(this)
421+
let dropdown = $(parent).children(Selector.DATA_TOGGLE)[0]
422+
if (typeof dropdown === 'undefined') {
423+
parent = $(parent).find(Selector.DROPDOWN_SHOWN)[0]
424+
if (typeof parent !== 'undefined') {
425+
dropdown = $(parent).children(Selector.DATA_TOGGLE)[0]
426+
}
427+
}
418428
const isActive = $(parent).hasClass(ClassName.SHOW)
419429

420430
if (!isActive && (event.which !== ESCAPE_KEYCODE || event.which !== SPACE_KEYCODE) ||
@@ -429,7 +439,13 @@ const Dropdown = (($) => {
429439
return
430440
}
431441

432-
const items = $(parent).find(Selector.VISIBLE_ITEMS).get()
442+
const context = $(dropdown).data(DATA_KEY)
443+
let items = null
444+
if (context._config.container && Util.isElement(context._config.container)) {
445+
items = $(context._menu).find(Selector.ACTIVE_ITEMS).get()
446+
} else {
447+
items = $(parent).find(Selector.VISIBLE_ITEMS).get()
448+
}
433449

434450
if (!items.length) {
435451
return

0 commit comments

Comments
 (0)