diff options
author | alpadev <2838324+alpadev@users.noreply.github.com> | 2021-04-11 18:34:46 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-11 18:34:46 +0300 |
commit | ad10f00d5e073f60b8d86d03812742b97037c336 (patch) | |
tree | 631cd7622af3eee5183baf9f01d877d7a4f7587e /js | |
parent | 566451230f5c87c3d7515af02995895df610b8ac (diff) |
refactor: make static `selectMenuItem` method private (#33589)
Diffstat (limited to 'js')
-rw-r--r-- | js/src/dropdown.js | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/js/src/dropdown.js b/js/src/dropdown.js index b126d3196a..ae440e4724 100644 --- a/js/src/dropdown.js +++ b/js/src/dropdown.js @@ -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) } } |