diff options
| author | Johann-S <[email protected]> | 2017-11-30 10:54:27 +0100 |
|---|---|---|
| committer | Johann-S <[email protected]> | 2018-12-05 16:02:59 +0100 |
| commit | b16127fc105f159ebd06b02df2853941b2aba67c (patch) | |
| tree | 45f5a0138c633e0e3aa6bd5357ffef4d14c8bc6f /js/src | |
| parent | 850d99bb13b895b83a860c38092755253ceb5b4a (diff) | |
| download | bootstrap-b16127fc105f159ebd06b02df2853941b2aba67c.tar.xz bootstrap-b16127fc105f159ebd06b02df2853941b2aba67c.zip | |
Allow Tooltips/Popovers to work in shadow DOM
Diffstat (limited to 'js/src')
| -rw-r--r-- | js/src/tooltip.js | 3 | ||||
| -rw-r--r-- | js/src/util.js | 23 |
2 files changed, 25 insertions, 1 deletions
diff --git a/js/src/tooltip.js b/js/src/tooltip.js index 1c40dfed3..9fa53a71b 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -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 ) diff --git a/js/src/util.js b/js/src/util.js index e9665d24f..1d804cf9d 100644 --- a/js/src/util.js +++ b/js/src/util.js @@ -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) } } |
