File tree 1 file changed +7
-8
lines changed
packages/@headlessui-react/src/utils
1 file changed +7
-8
lines changed Original file line number Diff line number Diff line change 1
- import type { MutableRefObject } from 'react'
2
- import { env } from './env'
1
+ import type { MutableRefObject } from 'react'
2
+ import { env } from './env'
3
3
4
4
export function getOwnerDocument < T extends Element | MutableRefObject < Element | null > > (
5
5
element : T | null | undefined
6
- ) {
6
+ ) : Document | null {
7
7
if ( env . isServer ) return null
8
- if ( element instanceof Node ) return element . ownerDocument
9
- if ( element ?. hasOwnProperty ( 'current' ) ) {
10
- if ( element . current instanceof Node ) return element . current . ownerDocument
11
- }
8
+ if ( ! element ) return document
9
+ if ( 'ownerDocument' in element ) return element . ownerDocument
10
+ if ( 'current' in element ) return element . current ?. ownerDocument ?? document
12
11
13
- return document
12
+ return null
14
13
}
You can’t perform that action at this time.
0 commit comments