mirror of
https://github.com/twbs/bootstrap.git
synced 2024-12-01 13:24:25 +01:00
refactor: make static selectMenuItem
method private (#33589)
This commit is contained in:
parent
566451230f
commit
ad10f00d5e
@ -356,6 +356,31 @@ class Dropdown extends BaseComponent {
|
||||
}
|
||||
}
|
||||
|
||||
_selectMenuItem(event) {
|
||||
const items = SelectorEngine.find(SELECTOR_VISIBLE_ITEMS, this._menu).filter(isVisible)
|
||||
|
||||
if (!items.length) {
|
||||
return
|
||||
}
|
||||
|
||||
let index = items.indexOf(event.target)
|
||||
|
||||
// Up
|
||||
if (event.key === ARROW_UP_KEY && index > 0) {
|
||||
index--
|
||||
}
|
||||
|
||||
// Down
|
||||
if (event.key === ARROW_DOWN_KEY && index < items.length - 1) {
|
||||
index++
|
||||
}
|
||||
|
||||
// index is -1 if the first keydown is an ArrowUp
|
||||
index = index === -1 ? 0 : index
|
||||
|
||||
items[index].focus()
|
||||
}
|
||||
|
||||
// Static
|
||||
|
||||
static dropdownInterface(element, config) {
|
||||
@ -449,31 +474,6 @@ class Dropdown extends BaseComponent {
|
||||
}
|
||||
}
|
||||
|
||||
static selectMenuItem(parent, event) {
|
||||
const items = SelectorEngine.find(SELECTOR_VISIBLE_ITEMS, parent).filter(isVisible)
|
||||
|
||||
if (!items.length) {
|
||||
return
|
||||
}
|
||||
|
||||
let index = items.indexOf(event.target)
|
||||
|
||||
// Up
|
||||
if (event.key === ARROW_UP_KEY && index > 0) {
|
||||
index--
|
||||
}
|
||||
|
||||
// Down
|
||||
if (event.key === ARROW_DOWN_KEY && index < items.length - 1) {
|
||||
index++
|
||||
}
|
||||
|
||||
// index is -1 if the first keydown is an ArrowUp
|
||||
index = index === -1 ? 0 : index
|
||||
|
||||
items[index].focus()
|
||||
}
|
||||
|
||||
static getParentFromElement(element) {
|
||||
return getElementFromSelector(element) || element.parentNode
|
||||
}
|
||||
@ -525,7 +525,7 @@ class Dropdown extends BaseComponent {
|
||||
return
|
||||
}
|
||||
|
||||
Dropdown.selectMenuItem(Dropdown.getParentFromElement(this), event)
|
||||
Dropdown.getInstance(getToggleButton())._selectMenuItem(event)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user