Skip to content

Commit

Permalink
refactor/add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
caseyjhol committed Mar 18, 2021
1 parent b5f3d91 commit f08dae5
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions js/src/dropdown.js
Expand Up @@ -375,8 +375,14 @@ class Dropdown extends BaseComponent {
}

static clearMenus(event) {
if (event && (event.button === RIGHT_MOUSE_BUTTON || (event.type === 'keyup' && event.key !== TAB_KEY))) {
return
if (event) {
if (event.button === RIGHT_MOUSE_BUTTON || (event.type === 'keyup' && event.key !== TAB_KEY)) {
return
}

if (/input|select|textarea|form/i.test(event.target.tagName)) {
return
}
}

const toggles = SelectorEngine.find(SELECTOR_DATA_TOGGLE)
Expand All @@ -401,16 +407,13 @@ class Dropdown extends BaseComponent {
}

if (event) {
const dropdownForm = dropdownMenu.querySelector('form')

if ([context._element, dropdownForm].some(element => event.composedPath().includes(element))) {
// Don't close the menu if the clicked element or one of its parents is the dropdown button
if ([context._element].some(element => event.composedPath().includes(element))) {
continue
}

if (((event.type === 'click' &&
/input|textarea/i.test(event.target.tagName)) ||
(event.type === 'keyup' && event.key === TAB_KEY)) &&
dropdownMenu.contains(event.target)) {
// Tab navigation through the dropdown menu shouldn't close the menu
if (event.type === 'keyup' && event.key === TAB_KEY && dropdownMenu.contains(event.target)) {
continue
}
}
Expand Down

0 comments on commit f08dae5

Please sign in to comment.