mirror of
https://github.com/twbs/bootstrap.git
synced 2025-03-15 15:29:22 +01:00
Dropdown: rename vars
This commit is contained in:
parent
0686fa00f0
commit
21e5618ba7
@ -405,21 +405,23 @@ class Dropdown extends BaseComponent {
|
|||||||
// - If trigger inside the menu => not a dropdown command
|
// - If trigger inside the menu => not a dropdown command
|
||||||
|
|
||||||
const isInput = /input|textarea/i.test(event.target.tagName)
|
const isInput = /input|textarea/i.test(event.target.tagName)
|
||||||
const eventKey = event.key
|
const isEscapeEvent = event.key === ESCAPE_KEY
|
||||||
if (!isInput && ![ARROW_UP_KEY, ARROW_DOWN_KEY, ESCAPE_KEY].includes(eventKey)) {
|
const isUpOrDownEvent = [ARROW_UP_KEY, ARROW_DOWN_KEY].includes(event.key)
|
||||||
|
|
||||||
|
if (!isInput && !(isUpOrDownEvent || isEscapeEvent)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isInput) {
|
if (isInput) {
|
||||||
// eslint-disable-next-line unicorn/no-lonely-if
|
// eslint-disable-next-line unicorn/no-lonely-if
|
||||||
if (eventKey !== ESCAPE_KEY && (![ARROW_UP_KEY, ARROW_DOWN_KEY].includes(eventKey) || event.target.closest(SELECTOR_MENU))) {
|
if (!isEscapeEvent && (!isUpOrDownEvent || event.target.closest(SELECTOR_MENU))) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const isActive = this.classList.contains(CLASS_NAME_SHOW)
|
const isActive = this.classList.contains(CLASS_NAME_SHOW)
|
||||||
|
|
||||||
if (!isActive && event.key === ESCAPE_KEY) {
|
if (!isActive && isEscapeEvent) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -433,12 +435,12 @@ class Dropdown extends BaseComponent {
|
|||||||
const getToggleButton = this.matches(SELECTOR_DATA_TOGGLE) ? this : SelectorEngine.prev(this, SELECTOR_DATA_TOGGLE)[0]
|
const getToggleButton = this.matches(SELECTOR_DATA_TOGGLE) ? this : SelectorEngine.prev(this, SELECTOR_DATA_TOGGLE)[0]
|
||||||
const instance = Dropdown.getOrCreateInstance(getToggleButton)
|
const instance = Dropdown.getOrCreateInstance(getToggleButton)
|
||||||
|
|
||||||
if (event.key === ESCAPE_KEY) {
|
if (isEscapeEvent) {
|
||||||
instance.hide()
|
instance.hide()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.key === ARROW_UP_KEY || event.key === ARROW_DOWN_KEY) {
|
if (isUpOrDownEvent) {
|
||||||
instance.show()
|
instance.show()
|
||||||
instance._selectMenuItem(event)
|
instance._selectMenuItem(event)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user