1
- import { CSSProperties , useCallback , useEffect , useState } from "react" ;
1
+ import {
2
+ CSSProperties ,
3
+ RefObject ,
4
+ useCallback ,
5
+ useEffect ,
6
+ useState ,
7
+ } from "react" ;
2
8
import { TransitionProps } from "react-transition-group/Transition" ;
3
9
import {
4
10
FixedPositionOptions ,
@@ -10,7 +16,16 @@ import {
10
16
} from "@react-md/utils" ;
11
17
12
18
export type FixedToFunction = ( ) => HTMLElement | null ;
13
- export type FixedTo = string | HTMLElement | null | FixedToFunction ;
19
+
20
+ /**
21
+ * @remarks \@since 2.8.0 Supports `RefObject` implementation.
22
+ */
23
+ export type FixedTo =
24
+ | RefObject < HTMLElement | null >
25
+ | FixedToFunction
26
+ | HTMLElement
27
+ | string
28
+ | null ;
14
29
export type OptionalFixedPositionOptions = Omit <
15
30
FixedPositionOptions ,
16
31
"container" | "element"
@@ -86,19 +101,22 @@ function getFixedTo(fixedTo: FixedTo): HTMLElement | null {
86
101
return null ;
87
102
}
88
103
89
- const t = typeof fixedTo ;
90
- switch ( t ) {
91
- case "string" :
92
- fixedTo = fixedTo as string ;
93
- return (
94
- document . getElementById ( fixedTo ) ||
95
- document . querySelector < HTMLElement > ( fixedTo )
96
- ) ;
97
- case "function" :
98
- return ( fixedTo as FixedToFunction ) ( ) ;
99
- default :
100
- return fixedTo as HTMLElement ;
104
+ if ( typeof fixedTo === "string" ) {
105
+ return (
106
+ document . getElementById ( fixedTo ) ||
107
+ document . querySelector < HTMLElement > ( fixedTo )
108
+ ) ;
101
109
}
110
+
111
+ if ( typeof fixedTo === "function" ) {
112
+ return fixedTo ( ) ;
113
+ }
114
+
115
+ if ( "current" in fixedTo ) {
116
+ return fixedTo . current ;
117
+ }
118
+
119
+ return fixedTo ;
102
120
}
103
121
104
122
interface ReturnValue extends Required < TransitionHooks > {
0 commit comments