@@ -34,7 +34,10 @@ function returnEmptyString() {
34
34
return '' ;
35
35
}
36
36
37
- function returnDocument ( ) {
37
+ function returnDocument ( element ?: HTMLElement ) {
38
+ if ( element ) {
39
+ return element . ownerDocument ;
40
+ }
38
41
return window . document ;
39
42
}
40
43
@@ -70,7 +73,7 @@ export interface TriggerProps {
70
73
focusDelay ?: number ;
71
74
blurDelay ?: number ;
72
75
getPopupContainer ?: ( node : HTMLElement ) => HTMLElement ;
73
- getDocument ?: ( ) => HTMLDocument ;
76
+ getDocument ?: ( element ?: HTMLElement ) => HTMLDocument ;
74
77
forceRender ?: boolean ;
75
78
destroyPopupOnHide ?: boolean ;
76
79
mask ?: boolean ;
@@ -215,7 +218,7 @@ export function generateTrigger(
215
218
! this . clickOutsideHandler &&
216
219
( this . isClickToHide ( ) || this . isContextMenuToShow ( ) )
217
220
) {
218
- currentDocument = props . getDocument ( ) ;
221
+ currentDocument = props . getDocument ( this . getRootDomNode ( ) ) ;
219
222
this . clickOutsideHandler = addEventListener (
220
223
currentDocument ,
221
224
'mousedown' ,
@@ -224,7 +227,7 @@ export function generateTrigger(
224
227
}
225
228
// always hide on mobile
226
229
if ( ! this . touchOutsideHandler ) {
227
- currentDocument = currentDocument || props . getDocument ( ) ;
230
+ currentDocument = currentDocument || props . getDocument ( this . getRootDomNode ( ) ) ;
228
231
this . touchOutsideHandler = addEventListener (
229
232
currentDocument ,
230
233
'touchstart' ,
@@ -233,7 +236,7 @@ export function generateTrigger(
233
236
}
234
237
// close popup when trigger type contains 'onContextMenu' and document is scrolling.
235
238
if ( ! this . contextMenuOutsideHandler1 && this . isContextMenuToShow ( ) ) {
236
- currentDocument = currentDocument || props . getDocument ( ) ;
239
+ currentDocument = currentDocument || props . getDocument ( this . getRootDomNode ( ) ) ;
237
240
this . contextMenuOutsideHandler1 = addEventListener (
238
241
currentDocument ,
239
242
'scroll' ,
@@ -559,7 +562,7 @@ export function generateTrigger(
559
562
560
563
let mountNode : HTMLElement ;
561
564
if ( ! getPopupContainer ) {
562
- mountNode = getDocument ( ) . body ;
565
+ mountNode = getDocument ( this . getRootDomNode ( ) ) . body ;
563
566
} else if ( domNode || getPopupContainer . length === 0 ) {
564
567
// Compatible for legacy getPopupContainer with domNode argument.
565
568
// If no need `domNode` argument, will call directly.
@@ -578,7 +581,8 @@ export function generateTrigger(
578
581
} ;
579
582
580
583
getContainer = ( ) => {
581
- const popupContainer = document . createElement ( 'div' ) ;
584
+ const { getDocument } = this . props ;
585
+ const popupContainer = getDocument ( this . getRootDomNode ( ) ) . createElement ( 'div' ) ;
582
586
// Make sure default popup container will never cause scrollbar appearing
583
587
// https://github.com/react-component/trigger/issues/41
584
588
popupContainer . style . position = 'absolute' ;
0 commit comments