1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-18 03:11:19 +02:00

Add getNextActiveElement helper function to utils, replacing custom implementation through components (#33608)

This commit is contained in:
GeoSot
2021-05-19 01:23:52 +03:00
committed by GitHub
parent 372890b67b
commit df72a21fa8
4 changed files with 76 additions and 31 deletions

View File

@@ -16,6 +16,7 @@ import {
isVisible,
isRTL,
noop,
getNextActiveElement,
typeCheckConfig
} from './util/index'
import Data from './dom/data'
@@ -354,28 +355,17 @@ class Dropdown extends BaseComponent {
}
_selectMenuItem(event) {
if (![ARROW_UP_KEY, ARROW_DOWN_KEY].includes(event.key)) {
return
}
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()
getNextActiveElement(items, event.target, event.key === ARROW_DOWN_KEY, false).focus()
}
// Static