1
1
import { getPlatform } from "@fern-api/ui-core-utils" ;
2
2
import { FernButton , FernInput } from "@fern-docs/components" ;
3
3
import { useKeyboardCommand , useKeyboardPress } from "@fern-ui/react-commons" ;
4
+ import { composeRefs } from "@radix-ui/react-compose-refs" ;
4
5
import { Search , Xmark } from "iconoir-react" ;
5
6
import { atom , useSetAtom } from "jotai" ;
6
7
import {
7
8
ReactElement ,
8
9
forwardRef ,
9
10
useCallback ,
10
11
useEffect ,
11
- useImperativeHandle ,
12
12
useRef ,
13
13
useState ,
14
14
} from "react" ;
@@ -26,7 +26,7 @@ export const SEARCH_BOX_MOUNTED = atom(false);
26
26
export const SearchBox = forwardRef < HTMLInputElement , SearchBoxProps > (
27
27
function SearchBox (
28
28
{ queryHook, className, inputClassName, placeholder } ,
29
- ref
29
+ forwardedRef
30
30
) : ReactElement {
31
31
const { query, refine } = useSearchBox ( { queryHook } ) ;
32
32
const [ inputValue , setInputValue ] = useState ( query ) ;
@@ -42,9 +42,6 @@ export const SearchBox = forwardRef<HTMLInputElement, SearchBoxProps>(
42
42
} ;
43
43
} , [ setMounted ] ) ;
44
44
45
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
46
- useImperativeHandle ( ref , ( ) => inputRef . current ! ) ;
47
-
48
45
const setQuery = useCallback (
49
46
( newQuery : string ) => {
50
47
setInputValue ( newQuery ) ;
@@ -113,7 +110,7 @@ export const SearchBox = forwardRef<HTMLInputElement, SearchBoxProps>(
113
110
} }
114
111
>
115
112
< input
116
- ref = { inputRef }
113
+ ref = { composeRefs ( inputRef , forwardedRef ) }
117
114
className = { inputClassName }
118
115
autoComplete = "off"
119
116
autoCorrect = "off"
@@ -137,15 +134,12 @@ export const SearchBox = forwardRef<HTMLInputElement, SearchBoxProps>(
137
134
export const SearchMobileBox = forwardRef < HTMLInputElement , SearchBoxProps > (
138
135
function SearchBox (
139
136
{ queryHook, className, inputClassName, placeholder, onFocus } ,
140
- ref
137
+ forwardedRef
141
138
) : ReactElement {
142
139
const { query, refine } = useSearchBox ( { queryHook } ) ;
143
140
const [ inputValue , setInputValue ] = useState ( query ) ;
144
141
const inputRef = useRef < HTMLInputElement > ( null ) ;
145
142
146
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
147
- useImperativeHandle ( ref , ( ) => inputRef . current ! ) ;
148
-
149
143
const setQuery = useCallback (
150
144
( newQuery : string ) => {
151
145
setInputValue ( newQuery ) ;
@@ -180,7 +174,7 @@ export const SearchMobileBox = forwardRef<HTMLInputElement, SearchBoxProps>(
180
174
} }
181
175
>
182
176
< FernInput
183
- ref = { inputRef }
177
+ ref = { composeRefs ( inputRef , forwardedRef ) }
184
178
className = { inputClassName }
185
179
autoComplete = "off"
186
180
autoCorrect = "off"
0 commit comments