diff --git a/public/index-rollup.html b/public/index-rollup.html index 4079e8f9..077f6190 100644 --- a/public/index-rollup.html +++ b/public/index-rollup.html @@ -7,7 +7,7 @@ Dev - React Tooltip - + diff --git a/src/App.tsx b/src/App.tsx index fd85b9ad..85c558f5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -33,25 +33,30 @@ function App() { > My button - + Check the dev console console.log('After show')} // eslint-disable-next-line no-console @@ -158,7 +163,7 @@ function App() { console.log('After show with click')} // eslint-disable-next-line no-console @@ -170,7 +175,7 @@ function App() { console.log('After show with delay')} // eslint-disable-next-line no-console @@ -202,7 +207,7 @@ function App() { @@ -231,7 +236,7 @@ function App() { (null) + + /** Set IsShadowRoot const */ + const isShadowDom = root instanceof ShadowRoot + /** * @todo Remove this in a future version (provider/wrapper method is deprecated) */ @@ -68,6 +74,29 @@ const Tooltip = ({ const shouldOpenOnClick = openOnClick || events.includes('click') + // If isShadowDom update to true, set the inline CSS to the shadow DOM + useEffect(() => { + if (typeof window !== 'undefined') { + if (isShadowDom && document.getElementById('style-rt')) { + const externalStylesheet = document.getElementById('style-rt') + const hrefCss = externalStylesheet!.getAttribute('href') + + // Fetch the CSS file, should be easier tbh but this works + fetch(hrefCss as string) + .then((response) => response.text()) + .then((cssContent) => { + const styleElement = document.createElement('style') + styleElement.textContent = cssContent + + // Add the new