1- import { CSSProperties , useCallback , useEffect , useState } from "react" ;
1+ import {
2+ CSSProperties ,
3+ RefObject ,
4+ useCallback ,
5+ useEffect ,
6+ useState ,
7+ } from "react" ;
28import { TransitionProps } from "react-transition-group/Transition" ;
39import {
410 FixedPositionOptions ,
@@ -10,7 +16,16 @@ import {
1016} from "@react-md/utils" ;
1117
1218export 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 ;
1429export type OptionalFixedPositionOptions = Omit <
1530 FixedPositionOptions ,
1631 "container" | "element"
@@ -86,19 +101,22 @@ function getFixedTo(fixedTo: FixedTo): HTMLElement | null {
86101 return null ;
87102 }
88103
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+ ) ;
101109 }
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 ;
102120}
103121
104122interface ReturnValue extends Required < TransitionHooks > {
0 commit comments