From 6579b9a6747f2ef7008f850c82d8bf55c948bdd5 Mon Sep 17 00:00:00 2001 From: Dmitry Sergienko Date: Thu, 19 Sep 2024 12:36:59 +0400 Subject: [PATCH 1/2] Fix popover doesn't show if its content or title is set dynamically after init --- js/src/tooltip.js | 4 ++-- js/tests/unit/popover.spec.js | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/js/src/tooltip.js b/js/src/tooltip.js index 097477f7a1a8..d4b3c9f0ed75 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -186,14 +186,14 @@ class Tooltip extends BaseComponent { throw new Error('Please use show on visible elements') } - if (!(this._isWithContent() && this._isEnabled)) { + if (!((this._isWithContent() || this._newContent != null) && this._isEnabled)) { return } const showEvent = EventHandler.trigger(this._element, this.constructor.eventName(EVENT_SHOW)) const shadowRoot = findShadowRoot(this._element) const isInTheDom = (shadowRoot || this._element.ownerDocument.documentElement).contains(this._element) - + if (showEvent.defaultPrevented || !isInTheDom) { return } diff --git a/js/tests/unit/popover.spec.js b/js/tests/unit/popover.spec.js index 1c81ba79279c..63642be3b210 100644 --- a/js/tests/unit/popover.spec.js +++ b/js/tests/unit/popover.spec.js @@ -56,6 +56,26 @@ describe('Popover', () => { }) describe('show', () => { + fit('should show a popover with no content after setContent', () => { + return new Promise(resolve => { + fixtureEl.innerHTML = 'BS twitter' + + const popoverEl = fixtureEl.querySelector('a') + const popover = Popover.getOrCreateInstance(popoverEl) + + popoverEl.addEventListener('shown.bs.popover', () => { + expect(document.querySelector('.popover')).not.toBeNull() + resolve() + }) + + popover.setContent({ + '.popover-body': 'some content' + }) + + popover.show() + }) + }) + it('should toggle a popover after show', () => { return new Promise(resolve => { fixtureEl.innerHTML = 'BS twitter' From 9fb58bb33fc6fe200acee38416a54be1b8abab09 Mon Sep 17 00:00:00 2001 From: Dmitry Sergienko Date: Thu, 19 Sep 2024 12:49:34 +0400 Subject: [PATCH 2/2] Fix lint and remove fit --- js/src/tooltip.js | 3 +-- js/tests/unit/popover.spec.js | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/js/src/tooltip.js b/js/src/tooltip.js index d4b3c9f0ed75..bcb044a3b3bf 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -186,14 +186,13 @@ class Tooltip extends BaseComponent { throw new Error('Please use show on visible elements') } - if (!((this._isWithContent() || this._newContent != null) && this._isEnabled)) { + if (!((this._isWithContent() || this._newContent !== null) && this._isEnabled)) { return } const showEvent = EventHandler.trigger(this._element, this.constructor.eventName(EVENT_SHOW)) const shadowRoot = findShadowRoot(this._element) const isInTheDom = (shadowRoot || this._element.ownerDocument.documentElement).contains(this._element) - if (showEvent.defaultPrevented || !isInTheDom) { return } diff --git a/js/tests/unit/popover.spec.js b/js/tests/unit/popover.spec.js index 63642be3b210..a1a86a0d9e80 100644 --- a/js/tests/unit/popover.spec.js +++ b/js/tests/unit/popover.spec.js @@ -56,7 +56,7 @@ describe('Popover', () => { }) describe('show', () => { - fit('should show a popover with no content after setContent', () => { + it('should show a popover with no content after setContent', () => { return new Promise(resolve => { fixtureEl.innerHTML = 'BS twitter'