Skip to content

Commit

Permalink
Update dropdown.js
Browse files Browse the repository at this point in the history
minor refactoring
  • Loading branch information
GeoSot committed Mar 31, 2022
1 parent 00d028e commit 5a0fe65
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions js/src/dropdown.js
Expand Up @@ -404,25 +404,22 @@ class Dropdown extends BaseComponent {
}

event.preventDefault()
if (!isEscapeEvent) {
event.stopPropagation()
}

const getToggleButton = SelectorEngine.findOne(SELECTOR_DATA_TOGGLE, event.delegateTarget.parentNode)
const instance = Dropdown.getOrCreateInstance(getToggleButton)

if (isEscapeEvent) {
if (getToggleButton.classList.contains(CLASS_NAME_SHOW)) {
instance.hide()
getToggleButton.focus()
event.stopPropagation()
}

if (isUpOrDownEvent) {
event.stopPropagation()
instance.show()
instance._selectMenuItem(event)
return
}

instance.show()
instance._selectMenuItem(event)
if (instance._isShown()) { // else is escape and we check if it is shown
event.stopPropagation()
instance.hide()
getToggleButton.focus()
}
}
}

Expand Down

0 comments on commit 5a0fe65

Please sign in to comment.