From ac1957309de96acfba49fe0ab6e9d9d1969318cd Mon Sep 17 00:00:00 2001 From: GeoSot Date: Fri, 10 Sep 2021 02:54:14 +0300 Subject: [PATCH 1/3] Force tooltip and popover to recreate content every time it opens --- js/src/tooltip.js | 28 ++++++++++++++-------------- js/tests/unit/tooltip.spec.js | 6 ++++-- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/js/src/tooltip.js b/js/src/tooltip.js index 92770091d1ab..650bf2b09227 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -115,6 +115,7 @@ class Tooltip extends BaseComponent { this._activeTrigger = {} this._popper = null this._templateFactory = null + this._newContent = null // Protected this.tip = null @@ -205,6 +206,12 @@ class Tooltip extends BaseComponent { return } + // todo v6 remove this OR make it optional + if (this.tip) { + this.tip.remove() + this.tip = null + } + const tip = this._getTipElement() this._element.setAttribute('aria-describedby', tip.getAttribute('id')) @@ -219,7 +226,7 @@ class Tooltip extends BaseComponent { if (this._popper) { this._popper.update() } else { - this._createPopper(tip) + this._popper = this._createPopper(tip) } tip.classList.add(CLASS_NAME_SHOW) @@ -305,7 +312,7 @@ class Tooltip extends BaseComponent { _getTipElement() { if (!this.tip) { - this.tip = this._createTipElement(this._getContentForTemplate()) + this.tip = this._createTipElement(this._newContent || this._getContentForTemplate()) } return this.tip @@ -335,17 +342,11 @@ class Tooltip extends BaseComponent { } setContent(content) { - let isShown = false - if (this.tip) { - isShown = this._isShown() + this._newContent = content + if (this._isShown()) { this.tip.remove() this.tip = null - } - - this._disposePopper() - this.tip = this._createTipElement(content) - - if (isShown) { + this._disposePopper() this.show() } } @@ -373,7 +374,7 @@ class Tooltip extends BaseComponent { } _getTitle() { - return this._config.title + return this._resolvePossibleFunction(this._config.title) || this._config.originalTitle } // Private @@ -394,7 +395,7 @@ class Tooltip extends BaseComponent { this._config.placement.call(this, tip, this._element) : this._config.placement const attachment = AttachmentMap[placement.toUpperCase()] - this._popper = Popper.createPopper(this._element, tip, this._getPopperConfig(attachment)) + return Popper.createPopper(this._element, tip, this._getPopperConfig(attachment)) } _getOffset() { @@ -592,7 +593,6 @@ class Tooltip extends BaseComponent { } config.originalTitle = this._element.getAttribute('title') || '' - config.title = this._resolvePossibleFunction(config.title) || config.originalTitle if (typeof config.title === 'number') { config.title = config.title.toString() } diff --git a/js/tests/unit/tooltip.spec.js b/js/tests/unit/tooltip.spec.js index 757ee9baf774..1431d837dd9a 100644 --- a/js/tests/unit/tooltip.spec.js +++ b/js/tests/unit/tooltip.spec.js @@ -185,7 +185,7 @@ describe('Tooltip', () => { const tooltipEl = fixtureEl.querySelector('a') const tooltip = new Tooltip(tooltipEl) - expect(tooltip._config.title).toEqual('Another tooltip') + expect(tooltip._getTitle()).toEqual('Another tooltip') }) }) @@ -848,7 +848,7 @@ describe('Tooltip', () => { }, 100) setTimeout(() => { - expect(insertedFunc).toHaveBeenCalledTimes(1) + expect(insertedFunc).toHaveBeenCalledTimes(2) resolve() }, 200) }, 0) @@ -1166,6 +1166,7 @@ describe('Tooltip', () => { tooltip.setContent({ '.tooltip-inner': 'foo' }) expect(tip()).not.toHaveClass('show') + tooltip.show() expect(tip().querySelector('.tooltip-inner').textContent).toEqual('foo') }) @@ -1229,6 +1230,7 @@ describe('Tooltip', () => { }) tooltip.setContent({ '.tooltip': { 0: childContent, jquery: 'jQuery' } }) + tooltip.show() expect(childContent.parentNode).toEqual(tooltip._getTipElement()) }) From 0bff037be59e496f66fe3f80a8afc58610d8ea00 Mon Sep 17 00:00:00 2001 From: "louismaxime.piton" Date: Wed, 15 Jun 2022 17:12:23 +0200 Subject: [PATCH 2/3] Fix --- js/src/popover.js | 2 +- js/src/tooltip.js | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/js/src/popover.js b/js/src/popover.js index 33768617c377..2ffccc82702c 100644 --- a/js/src/popover.js +++ b/js/src/popover.js @@ -55,7 +55,7 @@ class Popover extends Tooltip { // Overrides _isWithContent() { - return this._getTitle() || this._getContent() + return this._config.title || this._config.originalTitle || this._config.content } // Private diff --git a/js/src/tooltip.js b/js/src/tooltip.js index 650bf2b09227..7ddc8c9d31b9 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -307,7 +307,7 @@ class Tooltip extends BaseComponent { // Protected _isWithContent() { - return Boolean(this._getTitle()) + return this._config.title || this._config.originalTitle } _getTipElement() { @@ -344,8 +344,6 @@ class Tooltip extends BaseComponent { setContent(content) { this._newContent = content if (this._isShown()) { - this.tip.remove() - this.tip = null this._disposePopper() this.show() } From b888ccb0593647327861f960146619194ae51ec0 Mon Sep 17 00:00:00 2001 From: "louismaxime.piton" Date: Tue, 21 Jun 2022 16:42:25 +0200 Subject: [PATCH 3/3] fix(review) --- js/src/popover.js | 2 +- js/src/tooltip.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/src/popover.js b/js/src/popover.js index 2ffccc82702c..fa22ea8c9e41 100644 --- a/js/src/popover.js +++ b/js/src/popover.js @@ -55,7 +55,7 @@ class Popover extends Tooltip { // Overrides _isWithContent() { - return this._config.title || this._config.originalTitle || this._config.content + return Boolean(this._config.title || this._config.originalTitle || this._config.content) } // Private diff --git a/js/src/tooltip.js b/js/src/tooltip.js index 7ddc8c9d31b9..8cd3027e7550 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -307,7 +307,7 @@ class Tooltip extends BaseComponent { // Protected _isWithContent() { - return this._config.title || this._config.originalTitle + return Boolean(this._config.title || this._config.originalTitle) } _getTipElement() {