@@ -81,14 +81,16 @@ const useHideDelay = (
81
81
onHideCallbackRef . current ( ) ;
82
82
} ;
83
83
84
- document . addEventListener ( 'click' , handleDocumentClick ) ;
84
+ const { ownerDocument } = triggerRef . current ;
85
+
86
+ ownerDocument . addEventListener ( 'click' , handleDocumentClick ) ;
85
87
rootElement . addEventListener (
86
88
'wcstripe-tooltip-open' ,
87
89
handleHideElement
88
90
) ;
89
91
90
92
return ( ) => {
91
- document . removeEventListener ( 'click' , handleDocumentClick ) ;
93
+ ownerDocument . removeEventListener ( 'click' , handleDocumentClick ) ;
92
94
rootElement . removeEventListener (
93
95
'wcstripe-tooltip-open' ,
94
96
handleHideElement
@@ -185,14 +187,22 @@ const TooltipBase = ( {
185
187
186
188
const debouncedCalculation = debounce ( calculateTooltipPosition , 150 ) ;
187
189
188
- window . addEventListener ( 'resize' , debouncedCalculation ) ;
189
- document . addEventListener ( 'scroll' , debouncedCalculation ) ;
190
+ const { ownerDocument } = wrapperRef . current ;
191
+
192
+ ownerDocument . defaultView . addEventListener (
193
+ 'resize' ,
194
+ debouncedCalculation
195
+ ) ;
196
+ ownerDocument . addEventListener ( 'scroll' , debouncedCalculation ) ;
190
197
191
198
return ( ) => {
192
- window . removeEventListener ( 'resize' , debouncedCalculation ) ;
193
- document . removeEventListener ( 'scroll' , debouncedCalculation ) ;
199
+ ownerDocument . defaultView . removeEventListener (
200
+ 'resize' ,
201
+ debouncedCalculation
202
+ ) ;
203
+ ownerDocument . removeEventListener ( 'scroll' , debouncedCalculation ) ;
194
204
} ;
195
- } , [ isTooltipVisible , maxWidth ] ) ;
205
+ } , [ isTooltipVisible , maxWidth , wrapperRef ] ) ;
196
206
197
207
return (
198
208
< >
0 commit comments