Skip to content

Commit

Permalink
fix tooltip hide method when already hidden (#31115)
Browse files Browse the repository at this point in the history
Co-authored-by: XhmikosR <[email protected]>
  • Loading branch information
Hiws and XhmikosR authored Sep 24, 2020
1 parent a690a67 commit 43b4252
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions js/src/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions js/tests/unit/tooltip.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 43b4252

Please sign in to comment.