Skip to content

Commit 9d35880

Browse files
committed
feat: add event listener to handle style injection
1 parent 2ce8c44 commit 9d35880

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/components/TooltipController/TooltipController.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,14 @@ const TooltipController = ({
168168
setTooltipPositionStrategy(positionStrategy)
169169
}, [positionStrategy])
170170

171+
useEffect(() => {
172+
if (typeof window !== 'undefined') {
173+
// here we can do validations related to the props before inject the styles,
174+
// we can also send something into the 'detail' to the inject style function
175+
window.dispatchEvent(new CustomEvent('rt_inject_styles', { detail: {} }))
176+
}
177+
}, [])
178+
171179
useEffect(() => {
172180
const elementRefs = new Set(anchorRefs)
173181

src/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ import type { ITooltipWrapper } from './components/TooltipProvider/TooltipProvid
2020
const TooltipCoreStyles = 'react-tooltip-core-css-placeholder'
2121
const TooltipStyles = 'react-tooltip-css-placeholder'
2222

23-
injectStyle({ css: TooltipCoreStyles, type: 'core' })
24-
injectStyle({ css: TooltipStyles })
23+
if (typeof window !== 'undefined') {
24+
window.addEventListener('rt_inject_styles', () => {
25+
injectStyle({ css: TooltipCoreStyles, type: 'core' })
26+
injectStyle({ css: TooltipStyles })
27+
})
28+
}
2529

2630
export { TooltipController as Tooltip } from './components/TooltipController'
2731
export { TooltipProvider, TooltipWrapper } from './components/TooltipProvider'

0 commit comments

Comments
 (0)