aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorGeoSot <[email protected]>2021-08-27 03:16:51 +0300
committerGeoSot <[email protected]>2021-09-29 02:55:20 +0300
commitd07858170ada7c41a6ce82325653f6c871301bd2 (patch)
tree965d831e289cd1b6a1d000d0fd815fcb386482a2 /js
parent145f076e88ec484fe1073c17d171a3769a0c214c (diff)
downloadbootstrap-gs-make-template_factory.tar.xz
bootstrap-gs-make-template_factory.zip
Fix `setContent`gs-make-template_factory
Remove 'data-bs-original-title' trick fix class selector on `_popperConfig`
Diffstat (limited to 'js')
-rw-r--r--js/src/tooltip.js37
1 files changed, 17 insertions, 20 deletions
diff --git a/js/src/tooltip.js b/js/src/tooltip.js
index fabc6b020..5e29a5aea 100644
--- a/js/src/tooltip.js
+++ b/js/src/tooltip.js
@@ -107,6 +107,7 @@ const HOVER_STATE_SHOW = 'show'
const HOVER_STATE_OUT = 'out'
const SELECTOR_TOOLTIP_INNER = '.tooltip-inner'
+const SELECTOR_TOOLTIP_ARROW = '.tooltip-arrow'
const SELECTOR_MODAL = `.${CLASS_NAME_MODAL}`
const EVENT_MODAL_HIDE = 'hide.bs.modal'
@@ -234,14 +235,6 @@ class Tooltip extends BaseComponent {
return
}
- // A trick to recreate a tooltip in case a new title is given by using the NOT documented `data-bs-original-title`
- // This will be removed later in favor of a `setContent` method
- if (this.constructor.NAME === 'tooltip' && this.tip && this.getTitle() !== this.tip.querySelector(SELECTOR_TOOLTIP_INNER).innerHTML) {
- this._disposePopper()
- this.tip.remove()
- this.tip = null
- }
-
const tip = this.getTipElement()
const tipId = getUID(this.constructor.NAME)
@@ -372,7 +365,19 @@ class Tooltip extends BaseComponent {
}
setContent(content) {
+ let isShown = false
+ if (this.tip) {
+ isShown = this.tip.classList.contains(CLASS_NAME_SHOW)
+ this.tip.remove()
+ }
+
+ this._disposePopper()
+
this.tip = this._getTemplateFactory(content).toHtml()
+
+ if (isShown) {
+ this.show()
+ }
}
_getTemplateFactory(content) {
@@ -397,9 +402,7 @@ class Tooltip extends BaseComponent {
}
getTitle() {
- const title = this._element.getAttribute('data-bs-original-title') || this._config.title
-
- return this._resolvePossibleFunction(title)
+ return this._resolvePossibleFunction(this._config.title) || this._element.getAttribute('title')
}
updateAttachment(attachment) {
@@ -463,7 +466,7 @@ class Tooltip extends BaseComponent {
{
name: 'arrow',
options: {
- element: `.${this.constructor.NAME}-arrow`
+ element: SELECTOR_TOOLTIP_ARROW
}
},
{
@@ -534,15 +537,9 @@ class Tooltip extends BaseComponent {
_fixTitle() {
const title = this._element.getAttribute('title')
- const originalTitleType = typeof this._element.getAttribute('data-bs-original-title')
-
- if (title || originalTitleType !== 'string') {
- this._element.setAttribute('data-bs-original-title', title || '')
- if (title && !this._element.getAttribute('aria-label') && !this._element.textContent) {
- this._element.setAttribute('aria-label', title)
- }
- this._element.setAttribute('title', '')
+ if (title && !this._element.getAttribute('aria-label') && !this._element.textContent) {
+ this._element.setAttribute('aria-label', title)
}
}