Skip to content

Commit 17d64f4

Browse files
committed
Fix keyboard navigation
1 parent 712c986 commit 17d64f4

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

js/src/dropdown.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ const Dropdown = (($) => {
5454
}
5555

5656
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)'
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(.${ClassName.DISABLED})`,
62+
ACTIVE_ITEMS : `.dropdown-item:not(.${ClassName.DISABLED})`,
63+
DROPDOWN_SHOWN : `.${ClassName.SHOW} > [data-toggle="dropdown"]`
6264
}
6365

6466
const AttachmentMap = {
@@ -414,7 +416,14 @@ const Dropdown = (($) => {
414416
return
415417
}
416418

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

420429
if (!isActive && (event.which !== ESCAPE_KEYCODE || event.which !== SPACE_KEYCODE) ||
@@ -429,7 +438,13 @@ const Dropdown = (($) => {
429438
return
430439
}
431440

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

434449
if (!items.length) {
435450
return

0 commit comments

Comments
 (0)