@@ -5,6 +5,8 @@ import { useCallback, useEffect, useRef } from 'react';
5
5
import useEventCallback from '@restart/hooks/useEventCallback' ;
6
6
import warning from 'warning' ;
7
7
8
+ import ownerDocument from './utils/ownerDocument' ;
9
+
8
10
const escapeKeyCode = 27 ;
9
11
const noop = ( ) => { } ;
10
12
@@ -69,23 +71,25 @@ function useRootClose(
69
71
useEffect ( ( ) => {
70
72
if ( disabled || ref == null ) return undefined ;
71
73
74
+ const doc = ownerDocument ( ref . current ) ;
75
+
72
76
// Use capture for this listener so it fires before React's listener, to
73
77
// avoid false positives in the contains() check below if the target DOM
74
78
// element is removed in the React mouse callback.
75
79
const removeMouseCaptureListener = listen (
76
- document ,
80
+ doc ,
77
81
clickTrigger ,
78
82
handleMouseCapture ,
79
83
true ,
80
84
) ;
81
85
82
- const removeMouseListener = listen ( document , clickTrigger , handleMouse ) ;
83
- const removeKeyupListener = listen ( document , 'keyup' , handleKeyUp ) ;
86
+ const removeMouseListener = listen ( doc , clickTrigger , handleMouse ) ;
87
+ const removeKeyupListener = listen ( doc , 'keyup' , handleKeyUp ) ;
84
88
85
89
let mobileSafariHackListeners = [ ] ;
86
- if ( 'ontouchstart' in document . documentElement ) {
90
+ if ( 'ontouchstart' in doc . documentElement ) {
87
91
mobileSafariHackListeners = [ ] . slice
88
- . call ( document . body . children )
92
+ . call ( doc . body . children )
89
93
. map ( el => listen ( el , 'mousemove' , noop ) ) ;
90
94
}
91
95
0 commit comments