@@ -9,15 +9,12 @@ function SearchBarChild({ initialSubjects }: { initialSubjects: string[] }) {
9
9
const router = useRouter ( ) ;
10
10
const [ searchText , setSearchText ] = useState ( "" ) ;
11
11
const [ suggestions , setSuggestions ] = useState < string [ ] > ( [ ] ) ;
12
- const [ isSearching , setIsSearching ] = useState ( false ) ;
13
12
const [ subjects ] = useState < string [ ] > ( initialSubjects ) ;
14
13
const suggestionsRef = useRef < HTMLUListElement | null > ( null ) ;
15
- const inputRef = useRef < HTMLInputElement | null > ( null ) ;
16
14
17
15
const handleSearchChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
18
16
const text = e . target . value ;
19
17
setSearchText ( text ) ;
20
- setIsSearching ( true ) ;
21
18
22
19
if ( text . length > 1 && subjects . length > 0 ) {
23
20
const filteredSuggestions = subjects . filter ( ( subject ) =>
@@ -32,18 +29,15 @@ function SearchBarChild({ initialSubjects }: { initialSubjects: string[] }) {
32
29
const handleSelectSuggestion = ( suggestion : string ) => {
33
30
setSearchText ( suggestion ) ;
34
31
setSuggestions ( [ ] ) ;
35
- setIsSearching ( false ) ;
36
32
router . push ( `/catalogue?subject=${ encodeURIComponent ( suggestion ) } ` ) ;
37
33
} ;
38
34
39
35
const handleClickOutside = ( event : MouseEvent ) => {
40
36
if (
41
37
suggestionsRef . current &&
42
- ! suggestionsRef . current . contains ( event . target as Node ) &&
43
- ! inputRef . current ?. contains ( event . target as Node )
38
+ ! suggestionsRef . current . contains ( event . target as Node )
44
39
) {
45
40
setSuggestions ( [ ] ) ;
46
- setIsSearching ( false ) ;
47
41
}
48
42
} ;
49
43
@@ -55,39 +49,35 @@ function SearchBarChild({ initialSubjects }: { initialSubjects: string[] }) {
55
49
} , [ ] ) ;
56
50
57
51
return (
58
- < div className = "mx-4 md:mx-0" >
52
+ < div className = "mx-4 md:mx-0 play " >
59
53
< form
60
54
className = "w-full max-w-xl"
61
55
onSubmit = { ( e ) => {
62
56
e . preventDefault ( ) ;
63
57
if ( searchText ) {
64
- setIsSearching ( false ) ;
65
58
router . push ( `/catalogue?subject=${ encodeURIComponent ( searchText ) } ` ) ;
66
59
}
67
60
} }
68
61
>
69
62
< div className = "relative" >
70
63
< Input
71
- ref = { inputRef }
72
64
type = "text"
73
65
value = { searchText }
74
66
onChange = { handleSearchChange }
75
- onFocus = { ( ) => setIsSearching ( true ) }
76
67
placeholder = "Search by subject..."
77
- className = "text-md w-full rounded-full border bg-[#434dba] px-4 py-6 pr-10 font-sans tracking-wider text-white shadow-sm placeholder:text-white focus:outline-none focus:ring-2"
68
+ className = "text-md w-full rounded-lg play bg-[#B2B8FF] dark:bg-[#7480FF66] px-4 py-6 pr-10 font-sans tracking-wider dark: text-white text-black shadow-sm placeholder:dark: text-white placeholder:text-black focus:outline-none focus:ring-2"
78
69
/>
79
70
< button
80
71
type = "submit"
81
72
className = "absolute inset-y-0 right-0 flex items-center pr-3"
82
73
>
83
- < Search className = "h-5 w-5 text-white" />
74
+ < Search className = "h-5 w-5 text-black dark:text- white" />
84
75
</ button >
85
- { isSearching &&
86
- ( suggestions . length > 0 ||
87
- ( searchText . length > 1 && subjects . length > 0 ) ) && (
76
+ { ( suggestions . length > 0 ||
77
+ ( searchText . length > 1 && subjects . length > 0 ) ) && (
88
78
< ul
89
79
ref = { suggestionsRef }
90
- className = "absolute z-20 mx-0.5 mt-2 w-full max-w-xl rounded-md border border-[#434dba] bg-white text-center shadow-lg dark:bg-[#030712] md:mx-0"
80
+ className = "absolute z-20 mx-0.5 mt-2 w-full max-w-xl rounded-md bg-white text-center shadow-lg dark:bg-[#030712] md:mx-0"
91
81
>
92
82
{ suggestions . length > 0 ? (
93
83
suggestions . map ( ( suggestion , index ) => (
@@ -112,4 +102,4 @@ function SearchBarChild({ initialSubjects }: { initialSubjects: string[] }) {
112
102
) ;
113
103
}
114
104
115
- export default SearchBarChild ;
105
+ export default SearchBarChild ;
0 commit comments