-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchbar.jsx
37 lines (32 loc) · 1.11 KB
/
Searchbar.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { FiSearch } from 'react-icons/fi';
const Searchbar = () => {
const navigate = useNavigate();
const [searchTerm, setSearchTerm] = useState('');
const handleSubmit = (e) => {
e.preventDefault();
navigate(`/search/${searchTerm}`);
};
return (
<form onSubmit={handleSubmit} autoComplete="off" className="p-2 text-gray-400 focus-within:text-gray-600">
<label htmlFor="search-field" className="sr-only">
Search all songs
</label>
<div className="flex flex-row justify-start items-center">
<FiSearch className="w-5 h-5 ml-4" />
<input
name="search-field"
autoComplete="off"
id="search-field"
placeholder="Search"
type="search"
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
className="flex-1 bg-transparent border-none outline-none placeholder-gray-500 text-base text-white p-4"
/>
</div>
</form>
);
};
export default Searchbar;