Skip to content

Commit

Permalink
Merge branch 'fix-dropdown-mobile-backdrop' into current
Browse files Browse the repository at this point in the history
* fix-dropdown-mobile-backdrop:
  Fix mobile backdrop
  Revert "Fix mobile backdrop"
  Fix mobile backdrop
  • Loading branch information
pvdlg committed Jan 27, 2017
2 parents c444c81 + f836ab9 commit 2d0a7fe
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions js/src/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,6 @@ const Dropdown = (($) => {
return false
}

if ('ontouchstart' in document.documentElement &&
!$(parent).closest(Selector.NAVBAR_NAV).length) {

// if mobile we use a backdrop because click events don't delegate
const dropdown = document.createElement('div')
dropdown.className = ClassName.BACKDROP
$(dropdown).insertBefore(this)
$(dropdown).on('click', Dropdown._clearMenus)
}

const relatedTarget = {
relatedTarget : this
}
Expand All @@ -116,6 +106,17 @@ const Dropdown = (($) => {
return false
}

// set the backdrop only if the dropdown menu will be opened
if ('ontouchstart' in document.documentElement &&
!$(parent).closest(Selector.NAVBAR_NAV).length) {

// if mobile we use a backdrop because click events don't delegate
const dropdown = document.createElement('div')
dropdown.className = ClassName.BACKDROP
$(dropdown).insertBefore(this)
$(dropdown).on('click', Dropdown._clearMenus)
}

this.focus()
this.setAttribute('aria-expanded', true)

Expand Down Expand Up @@ -164,11 +165,6 @@ const Dropdown = (($) => {
return
}

const backdrop = $(Selector.BACKDROP)[0]
if (backdrop) {
backdrop.parentNode.removeChild(backdrop)
}

const toggles = $.makeArray($(Selector.DATA_TOGGLE))

for (let i = 0; i < toggles.length; i++) {
Expand All @@ -193,6 +189,12 @@ const Dropdown = (($) => {
continue
}

// remove backdrop only if the dropdown menu will be hidden
const backdrop = $(parent).find(Selector.BACKDROP)[0]
if (backdrop) {
backdrop.parentNode.removeChild(backdrop)
}

toggles[i].setAttribute('aria-expanded', 'false')

$(parent)
Expand Down

0 comments on commit 2d0a7fe

Please sign in to comment.