Skip to content

Commit

Permalink
fix: escape key should not be handled when the dropdown is closed
Browse files Browse the repository at this point in the history
see #33465
  • Loading branch information
alpadev authored and GeoSot committed Mar 30, 2021
1 parent 0eaa413 commit 04022c9
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions js/src/dropdown.js
Expand Up @@ -488,25 +488,29 @@ class Dropdown extends BaseComponent {
return
}

const isActive = this.classList.contains(CLASS_NAME_SHOW)

if (!isActive && event.key === ESCAPE_KEY) {
return
}

event.preventDefault()
event.stopPropagation()

if (isDisabled(this)) {
return
}

const isActive = this.classList.contains(CLASS_NAME_SHOW)
const getButton = () => this.matches(SELECTOR_DATA_TOGGLE) ? this : SelectorEngine.prev(this, SELECTOR_DATA_TOGGLE)[0]

if (event.key === ESCAPE_KEY) {
const button = this.matches(SELECTOR_DATA_TOGGLE) ? this : SelectorEngine.prev(this, SELECTOR_DATA_TOGGLE)[0]
button.focus()
getButton().focus()
Dropdown.clearMenus()
return
}

if (!isActive && (event.key === ARROW_UP_KEY || event.key === ARROW_DOWN_KEY)) {
const button = this.matches(SELECTOR_DATA_TOGGLE) ? this : SelectorEngine.prev(this, SELECTOR_DATA_TOGGLE)[0]
button.click()
getButton().click()
return
}

Expand Down

0 comments on commit 04022c9

Please sign in to comment.