const NAME = 'tooltip'
const DATA_KEY = 'bs.tooltip'
const EVENT_KEY = `.${DATA_KEY}`
-const CLASS_PREFIX = 'bs-tooltip'
const DISALLOWED_ATTRIBUTES = new Set(['sanitize', 'allowList', 'sanitizeFn'])
const CLASS_NAME_FADE = 'fade'
this._element.setAttribute('aria-describedby', tip.getAttribute('id'))
- const placement = typeof this._config.placement === 'function' ?
- this._config.placement.call(this, tip, this._element) :
- this._config.placement
-
- const attachment = this._getAttachment(placement)
- this._addAttachmentClass(attachment)
-
const { container } = this._config
Data.set(tip, this.constructor.DATA_KEY, this)
if (this._popper) {
this._popper.update()
} else {
+ const placement = typeof this._config.placement === 'function' ?
+ 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))
}
tip.remove()
}
- this._cleanTipClass()
this._element.removeAttribute('aria-describedby')
EventHandler.trigger(this._element, this.constructor.Event.HIDDEN)
const tip = templateFactory.toHtml()
tip.classList.remove(CLASS_NAME_FADE, CLASS_NAME_SHOW)
+ // todo on v6 the following can be done on css only
+ tip.classList.add(`bs-${this.constructor.NAME}-auto`)
const tipId = getUID(this.constructor.NAME).toString()
options: {
element: SELECTOR_TOOLTIP_ARROW
}
- },
- {
- name: 'onChange',
- enabled: true,
- phase: 'afterWrite',
- fn: data => this._handlePopperPlacementChange(data)
- }
- ],
- onFirstUpdate: data => {
- if (data.options.placement !== data.placement) {
- this._handlePopperPlacementChange(data)
}
- }
+ ]
}
return {
}
}
- _addAttachmentClass(attachment) {
- this.getTipElement().classList.add(`${this._getBasicClassPrefix()}-${this.updateAttachment(attachment)}`)
- }
-
- _getAttachment(placement) {
- return AttachmentMap[placement.toUpperCase()]
- }
-
_setListeners() {
const triggers = this._config.trigger.split(' ')
return config
}
- _cleanTipClass() {
- const tip = this.getTipElement()
- const basicClassPrefixRegex = new RegExp(`(^|\\s)${this._getBasicClassPrefix()}\\S+`, 'g')
- const tabClass = tip.getAttribute('class').match(basicClassPrefixRegex)
- if (tabClass !== null && tabClass.length > 0) {
- for (const tClass of tabClass.map(token => token.trim())) {
- tip.classList.remove(tClass)
- }
- }
- }
-
- _getBasicClassPrefix() {
- return CLASS_PREFIX
- }
-
- _handlePopperPlacementChange(popperData) {
- const { state } = popperData
-
- if (!state) {
- return
- }
-
- this.tip = state.elements.popper
- this._cleanTipClass()
- this._addAttachmentClass(this._getAttachment(state.placement))
- }
-
_disposePopper() {
if (this._popper) {
this._popper.destroy()
})
tooltipEl.addEventListener('inserted.bs.tooltip', () => {
- expect(tooltip.getTipElement().classList.contains('bs-tooltip-bottom')).toEqual(true)
+ expect(tooltip.getTipElement().classList.contains('bs-tooltip-auto')).toEqual(true)
})
tooltipEl.addEventListener('shown.bs.tooltip', () => {
- const tooltipShown = document.querySelector('.tooltip')
-
- expect(tooltipShown.classList.contains('bs-tooltip-bottom')).toEqual(true)
+ expect(tooltip.getTipElement().classList.contains('bs-tooltip-auto')).toEqual(true)
+ expect(tooltip.getTipElement().getAttribute('data-popper-placement')).toEqual('bottom')
done()
})
setTimeout(() => {
expect(tooltip.getTipElement().classList.contains('show')).toEqual(true)
+ expect(document.querySelectorAll('.tooltip').length).toEqual(1)
done()
}, 200)
}, 0)
})
tooltipEl.addEventListener('inserted.bs.tooltip', () => {
- expect(tooltip.getTipElement().classList.contains('bs-tooltip-end')).toEqual(true)
+ expect(tooltip.getTipElement().classList.contains('bs-tooltip-auto')).toEqual(true)
done()
})
})
tooltipEl.addEventListener('inserted.bs.tooltip', () => {
- expect(tooltip.getTipElement().classList.contains('bs-tooltip-start')).toEqual(true)
+ expect(tooltip.getTipElement().classList.contains('bs-tooltip-auto')).toEqual(true)
done()
})