aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/twbs/bootstrap/js/src/dropdown.js
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2021-07-29 08:25:05 +0000
committerMario <mario@mariovavti.com>2021-07-29 08:25:05 +0000
commitd459dfac74e90c29950d49a82edc19fd913d435e (patch)
tree7bed5f2dbc318f87bbe0f4be2cde3dde09cd97c7 /vendor/twbs/bootstrap/js/src/dropdown.js
parentcec2f0d894b80f3affeb60cff2d4afa49a2019a8 (diff)
downloadvolse-hubzilla-d459dfac74e90c29950d49a82edc19fd913d435e.tar.gz
volse-hubzilla-d459dfac74e90c29950d49a82edc19fd913d435e.tar.bz2
volse-hubzilla-d459dfac74e90c29950d49a82edc19fd913d435e.zip
update to bootstrap 5.0.2
Diffstat (limited to 'vendor/twbs/bootstrap/js/src/dropdown.js')
-rw-r--r--vendor/twbs/bootstrap/js/src/dropdown.js45
1 files changed, 14 insertions, 31 deletions
diff --git a/vendor/twbs/bootstrap/js/src/dropdown.js b/vendor/twbs/bootstrap/js/src/dropdown.js
index 565edb892..681369b48 100644
--- a/vendor/twbs/bootstrap/js/src/dropdown.js
+++ b/vendor/twbs/bootstrap/js/src/dropdown.js
@@ -1,6 +1,6 @@
/**
* --------------------------------------------------------------------------
- * Bootstrap (v5.0.1): dropdown.js
+ * Bootstrap (v5.0.2): dropdown.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
@@ -16,9 +16,9 @@ import {
isVisible,
isRTL,
noop,
+ getNextActiveElement,
typeCheckConfig
} from './util/index'
-import Data from './dom/data'
import EventHandler from './dom/event-handler'
import Manipulator from './dom/manipulator'
import SelectorEngine from './dom/selector-engine'
@@ -353,40 +353,22 @@ class Dropdown extends BaseComponent {
}
}
- _selectMenuItem(event) {
+ _selectMenuItem({ key, target }) {
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()
+ // if target isn't included in items (e.g. when expanding the dropdown)
+ // allow cycling to get the last item in case key equals ARROW_UP_KEY
+ getNextActiveElement(items, target, key === ARROW_DOWN_KEY, !items.includes(target)).focus()
}
// Static
static dropdownInterface(element, config) {
- let data = Data.get(element, DATA_KEY)
- const _config = typeof config === 'object' ? config : null
-
- if (!data) {
- data = new Dropdown(element, _config)
- }
+ const data = Dropdown.getOrCreateInstance(element, config)
if (typeof config === 'string') {
if (typeof data[config] === 'undefined') {
@@ -411,7 +393,7 @@ class Dropdown extends BaseComponent {
const toggles = SelectorEngine.find(SELECTOR_DATA_TOGGLE)
for (let i = 0, len = toggles.length; i < len; i++) {
- const context = Data.get(toggles[i], DATA_KEY)
+ const context = Dropdown.getInstance(toggles[i])
if (!context || context._config.autoClose === false) {
continue
}
@@ -490,17 +472,18 @@ class Dropdown extends BaseComponent {
return
}
- if (!isActive && (event.key === ARROW_UP_KEY || event.key === ARROW_DOWN_KEY)) {
- getToggleButton().click()
+ if (event.key === ARROW_UP_KEY || event.key === ARROW_DOWN_KEY) {
+ if (!isActive) {
+ getToggleButton().click()
+ }
+
+ Dropdown.getInstance(getToggleButton())._selectMenuItem(event)
return
}
if (!isActive || event.key === SPACE_KEY) {
Dropdown.clearMenus()
- return
}
-
- Dropdown.getInstance(getToggleButton())._selectMenuItem(event)
}
}