File tree 1 file changed +12
-0
lines changed
1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { useEffect , useRef } from "react" ;
2
+
1
3
interface SearchInputProps {
2
4
searchQuery : string ;
3
5
setSearchQuery : ( query : string ) => void ;
4
6
}
5
7
export const SearchInput : React . FC <
6
8
SearchInputProps & React . HTMLProps < HTMLDivElement >
7
9
> = ( { searchQuery, setSearchQuery, ...props } ) => {
10
+ const ref = useRef < HTMLInputElement > ( null ) ;
11
+
12
+ useEffect ( ( ) => {
13
+ if ( ref . current ) {
14
+ // Autofocus the input field, without scrolling the page
15
+ ref . current . focus ( { preventScroll : true } ) ;
16
+ }
17
+ } , [ ] ) ;
18
+
8
19
return (
9
20
< div className = "relative flex w-full items-center gap-2" { ...props } >
10
21
< input
22
+ ref = { ref }
11
23
autoComplete = "off"
12
24
spellCheck = { false }
13
25
className = "inset-0 h-10 w-full resize-none rounded-lg border-2 border-brand-violet bg-pagebg p-3 text-base caret-brand-violet outline-none dark:text-white"
You can’t perform that action at this time.
0 commit comments