Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Bootstrap
bootstrap
Commits
6885d655
Commit
6885d655
authored
5 years ago
by
Johann-S
Browse files
Options
Download
Email Patches
Plain Diff
dropdown - destroy old popper.js references
parent
a5e725fa
2 merge requests
!31948
Examples/Floating-labels: fix bad behavior with autofill
,
!30064
test
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
js/src/dropdown/dropdown.js
+6
-6
js/src/dropdown/dropdown.js
js/src/dropdown/dropdown.spec.js
+38
-0
js/src/dropdown/dropdown.spec.js
with
44 additions
and
6 deletions
+44
-6
js/src/dropdown/dropdown.js
+
6
-
6
View file @
6885d655
...
...
@@ -155,10 +155,6 @@ class Dropdown {
// Disable totally Popper.js for Dropdown in Navbar
if
(
!
this
.
_inNavbar
)
{
/**
* Check for Popper dependency
* Popper - https://popper.js.org
*/
if
(
typeof
Popper
===
'
undefined
'
)
{
throw
new
TypeError
(
'
Bootstrap
\'
s dropdowns require Popper.js (https://popper.js.org)
'
)
}
...
...
@@ -251,7 +247,7 @@ class Dropdown {
EventHandler
.
off
(
this
.
_element
,
EVENT_KEY
)
this
.
_element
=
null
this
.
_menu
=
null
if
(
this
.
_popper
!==
null
)
{
if
(
this
.
_popper
)
{
this
.
_popper
.
destroy
()
this
.
_popper
=
null
}
...
...
@@ -259,7 +255,7 @@ class Dropdown {
update
()
{
this
.
_inNavbar
=
this
.
_detectNavbar
()
if
(
this
.
_popper
!==
null
)
{
if
(
this
.
_popper
)
{
this
.
_popper
.
scheduleUpdate
()
}
}
...
...
@@ -440,6 +436,10 @@ class Dropdown {
toggles
[
i
].
setAttribute
(
'
aria-expanded
'
,
'
false
'
)
if
(
context
.
_popper
)
{
context
.
_popper
.
destroy
()
}
dropdownMenu
.
classList
.
remove
(
ClassName
.
SHOW
)
parent
.
classList
.
remove
(
ClassName
.
SHOW
)
EventHandler
.
trigger
(
parent
,
Event
.
HIDDEN
,
relatedTarget
)
...
...
This diff is collapsed.
Click to expand it.
js/src/dropdown/dropdown.spec.js
+
38
-
0
View file @
6885d655
...
...
@@ -147,6 +147,44 @@ describe('Dropdown', () => {
dropdown
.
toggle
()
})
it
(
'
should destroy old popper references on toggle
'
,
done
=>
{
fixtureEl
.
innerHTML
=
[
'
<div class="first dropdown">
'
,
'
<button href="#" class="firstBtn btn" data-toggle="dropdown" aria-expanded="false">Dropdown</button>
'
,
'
<div class="dropdown-menu">
'
,
'
<a class="dropdown-item" href="#">Secondary link</a>
'
,
'
</div>
'
,
'
</div>
'
,
'
<div class="second dropdown">
'
,
'
<button href="#" class="secondBtn btn" data-toggle="dropdown" aria-expanded="false">Dropdown</button>
'
,
'
<div class="dropdown-menu">
'
,
'
<a class="dropdown-item" href="#">Secondary link</a>
'
,
'
</div>
'
,
'
</div>
'
].
join
(
''
)
const
btnDropdown1
=
fixtureEl
.
querySelector
(
'
.firstBtn
'
)
const
btnDropdown2
=
fixtureEl
.
querySelector
(
'
.secondBtn
'
)
const
firstDropdownEl
=
fixtureEl
.
querySelector
(
'
.first
'
)
const
secondDropdownEl
=
fixtureEl
.
querySelector
(
'
.second
'
)
const
dropdown1
=
new
Dropdown
(
btnDropdown1
)
const
dropdown2
=
new
Dropdown
(
btnDropdown2
)
firstDropdownEl
.
addEventListener
(
'
shown.bs.dropdown
'
,
()
=>
{
expect
(
firstDropdownEl
.
classList
.
contains
(
'
show
'
)).
toEqual
(
true
)
spyOn
(
dropdown1
.
_popper
,
'
destroy
'
)
dropdown2
.
toggle
()
done
()
})
secondDropdownEl
.
addEventListener
(
'
shown.bs.dropdown
'
,
()
=>
{
expect
(
dropdown1
.
_popper
.
destroy
).
toHaveBeenCalled
()
done
()
})
dropdown1
.
toggle
()
})
it
(
'
should toggle a dropdown and add/remove event listener on mobile
'
,
done
=>
{
fixtureEl
.
innerHTML
=
[
'
<div class="dropdown">
'
,
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets