1
0
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:
Johann-S
2017-11-30 10:54:27 +01:00
parent 850d99bb13
commit b16127fc10
6 changed files with 86 additions and 2 deletions

View File

@@ -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
)

View File

@@ -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)
}
}