@@ -11,12 +11,12 @@ import "./search.scss";
1111
1212type SearchProps = SearchAtoms & {
1313 anchorRef ?: React . RefObject < HTMLElement > ;
14+ searchInputRef ?: React . RefObject < HTMLInputElement > ;
1415 offsetX ?: number ;
1516 offsetY ?: number ;
1617 onSearch ?: ( search : string ) => void ;
1718 onNext ?: ( ) => void ;
1819 onPrev ?: ( ) => void ;
19- blockId ?: string ;
2020} ;
2121
2222const SearchComponent = ( {
@@ -28,13 +28,15 @@ const SearchComponent = ({
2828 wholeWord : wholeWordAtom ,
2929 isOpen : isOpenAtom ,
3030 anchorRef,
31+ searchInputRef : providedInputRef ,
3132 offsetX = 10 ,
3233 offsetY = 10 ,
3334 onSearch,
3435 onNext,
3536 onPrev,
36- blockId,
3737} : SearchProps ) => {
38+ const localInputRef = useRef < HTMLInputElement > ( null ) ;
39+ const inputRef = providedInputRef || localInputRef ;
3840 const [ isOpen , setIsOpen ] = useAtom < boolean > ( isOpenAtom ) ;
3941 const [ search , setSearch ] = useAtom < string > ( searchAtom ) ;
4042 const [ index , setIndex ] = useAtom < number > ( indexAtom ) ;
@@ -146,8 +148,9 @@ const SearchComponent = ({
146148 < >
147149 { isOpen && (
148150 < FloatingPortal >
149- < div className = "search-container" style = { { ...floatingStyles } } ref = { refs . setFloating } data-blockid = { blockId } >
151+ < div className = "search-container" style = { { ...floatingStyles } } ref = { refs . setFloating } >
150152 < Input
153+ ref = { inputRef }
151154 placeholder = "Search"
152155 value = { search }
153156 onChange = { setSearch }
@@ -190,7 +193,6 @@ type SearchOptions = {
190193 regex ?: boolean ;
191194 caseSensitive ?: boolean ;
192195 wholeWord ?: boolean ;
193- blockId ?: string ;
194196} ;
195197
196198export function useSearch ( options ?: SearchOptions ) : SearchProps {
@@ -207,15 +209,19 @@ export function useSearch(options?: SearchOptions): SearchProps {
207209 [ ]
208210 ) ;
209211 const anchorRef = options ?. anchorRef ?? useRef ( null ) ;
212+ const searchInputRef = useRef < HTMLInputElement > ( null ) ;
210213 useEffect ( ( ) => {
211214 if ( options ?. viewModel ) {
212215 options . viewModel . searchAtoms = searchAtoms ;
216+ // Store inputRef on viewModel for external access (e.g., keymodel.ts)
217+ ( options . viewModel as any ) . searchInputRef = searchInputRef ;
213218 return ( ) => {
214219 options . viewModel . searchAtoms = undefined ;
220+ ( options . viewModel as any ) . searchInputRef = undefined ;
215221 } ;
216222 }
217- } , [ options ?. viewModel ] ) ;
218- return { ...searchAtoms , anchorRef, blockId : options ?. blockId } ;
223+ } , [ options ?. viewModel , searchAtoms ] ) ;
224+ return { ...searchAtoms , anchorRef, searchInputRef } ;
219225}
220226
221227const createToggleButtonDecl = (
0 commit comments