File tree Expand file tree Collapse file tree 2 files changed +7
-6
lines changed
packages/next/src/next-devtools/dev-overlay Expand file tree Collapse file tree 2 files changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -37,8 +37,7 @@ const Dialog: React.FC<DialogProps> = function Dialog({
37
37
)
38
38
39
39
useOnClickOutside (
40
- // eslint-disable-next-line react-hooks/react-compiler -- TODO
41
- dialogRef . current ,
40
+ dialogRef ,
42
41
CSS_SELECTORS_TO_EXCLUDE_ON_CLICK_OUTSIDE ,
43
42
( e ) => {
44
43
e . preventDefault ( )
Original file line number Diff line number Diff line change 1
1
import * as React from 'react'
2
2
3
3
export function useOnClickOutside (
4
- el : Node | null ,
4
+ el : Node | React . RefObject < Node | null > | null ,
5
5
cssSelectorsToExclude : string [ ] ,
6
6
handler : ( ( e : MouseEvent | TouchEvent ) => void ) | undefined
7
7
) {
8
8
React . useEffect ( ( ) => {
9
- if ( el == null || handler == null ) {
9
+ // Support both direct nodes and ref objects
10
+ const element = el && 'current' in el ? el . current : el
11
+ if ( element == null || handler == null ) {
10
12
return
11
13
}
12
14
13
15
const listener = ( e : MouseEvent | TouchEvent ) => {
14
16
// Do nothing if clicking ref's element or descendent elements
15
- if ( ! el || el . contains ( e . target as Element ) ) {
17
+ if ( ! element || element . contains ( e . target as Element ) ) {
16
18
return
17
19
}
18
20
@@ -28,7 +30,7 @@ export function useOnClickOutside(
28
30
handler ( e )
29
31
}
30
32
31
- const root = el . getRootNode ( )
33
+ const root = element . getRootNode ( )
32
34
root . addEventListener ( 'mouseup' , listener as EventListener )
33
35
root . addEventListener ( 'touchend' , listener as EventListener , {
34
36
passive : false ,
You can’t perform that action at this time.
0 commit comments