Skip to content

Commit

Permalink
Fix keyboard navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann-S committed Nov 2, 2017
1 parent 712c986 commit 8d97095
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions js/src/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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) ||
Expand All @@ -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
Expand Down

0 comments on commit 8d97095

Please sign in to comment.