mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-08 14:46:34 +02:00
Allow Tooltips/Popovers to work in shadow DOM
This commit is contained in:
@@ -244,8 +244,9 @@ class Tooltip {
|
||||
if (this.isWithContent() && this._isEnabled) {
|
||||
$(this.element).trigger(showEvent)
|
||||
|
||||
const shadowRoot = Util.findShadowRoot(this.element)
|
||||
const isInTheDom = $.contains(
|
||||
this.element.ownerDocument.documentElement,
|
||||
shadowRoot !== null ? shadowRoot : this.element.ownerDocument.documentElement,
|
||||
this.element
|
||||
)
|
||||
|
||||
|
@@ -142,6 +142,29 @@ const Util = {
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
findShadowRoot(element) {
|
||||
if (!document.documentElement.attachShadow) {
|
||||
return null
|
||||
}
|
||||
|
||||
// Can find the shadow root otherwise it'll return the document
|
||||
if (typeof element.getRootNode === 'function') {
|
||||
const root = element.getRootNode()
|
||||
return root instanceof ShadowRoot ? root : null
|
||||
}
|
||||
|
||||
if (element instanceof ShadowRoot) {
|
||||
return element
|
||||
}
|
||||
|
||||
// when we don't find a shadow root
|
||||
if (!element.parentNode) {
|
||||
return null
|
||||
}
|
||||
|
||||
return Util.findShadowRoot(element.parentNode)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user