1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-09-29 23:09:05 +02:00

Automatically select an item in the dropdown when using arrow keys (#34052)

This commit is contained in:
alpadev
2021-05-22 09:58:52 +02:00
committed by GitHub
parent 8033975548
commit b39b665072
5 changed files with 61 additions and 26 deletions

View File

@@ -264,9 +264,9 @@ const execute = callback => {
const getNextActiveElement = (list, activeElement, shouldGetNext, isCycleAllowed) => {
let index = list.indexOf(activeElement)
// if the element does not exist in the list initialize it as the first element
// if the element does not exist in the list return an element depending on the direction and if cycle is allowed
if (index === -1) {
return list[0]
return list[!shouldGetNext && isCycleAllowed ? list.length - 1 : 0]
}
const listLength = list.length