aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorHiws <[email protected]>2020-09-24 13:55:38 +0200
committerGitHub <[email protected]>2020-09-24 14:55:38 +0300
commit43b4252a3487e419455f794e16d402a32d1ebe22 (patch)
tree324c4021ecab4298538c721d79a95776108ec8c3 /js
parenta690a67c7c57061ae74ad2d0d7714710ef216605 (diff)
downloadbootstrap-43b4252a3487e419455f794e16d402a32d1ebe22.tar.xz
bootstrap-43b4252a3487e419455f794e16d402a32d1ebe22.zip
fix tooltip hide method when already hidden (#31115)
Co-authored-by: XhmikosR <[email protected]>
Diffstat (limited to 'js')
-rw-r--r--js/src/tooltip.js4
-rw-r--r--js/tests/unit/tooltip.spec.js14
2 files changed, 18 insertions, 0 deletions
diff --git a/js/src/tooltip.js b/js/src/tooltip.js
index 9ad73328b..1bda97e38 100644
--- a/js/src/tooltip.js
+++ b/js/src/tooltip.js
@@ -331,6 +331,10 @@ class Tooltip {
}
hide() {
+ if (!this._popper) {
+ return
+ }
+
const tip = this.getTipElement()
const complete = () => {
if (this._hoverState !== HOVER_STATE_SHOW && tip.parentNode) {
diff --git a/js/tests/unit/tooltip.spec.js b/js/tests/unit/tooltip.spec.js
index 0a98096a4..3e5c91794 100644
--- a/js/tests/unit/tooltip.spec.js
+++ b/js/tests/unit/tooltip.spec.js
@@ -717,6 +717,20 @@ describe('Tooltip', () => {
tooltip.show()
})
+
+ it('should not throw error running hide if popper hasn\'t been shown', () => {
+ fixtureEl.innerHTML = '<div></div>'
+
+ const div = fixtureEl.querySelector('div')
+ const tooltip = new Tooltip(div)
+
+ try {
+ tooltip.hide()
+ expect().nothing()
+ } catch {
+ throw new Error('should not throw error')
+ }
+ })
})
describe('update', () => {