blob: d26415be33465a410d561524fb74c21514af92fa (
plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
|
/*
* OpenBills - Self hosted browser app to generate and keep track of simple invoices
* Version - 0
* Licensed under the MIT license - https://opensource.org/licenses/MIT
*
* Copyright (c) 2021 Vidhu Kant Sharma
*/
import React, { useState } from "react";
import "./SearchBar.scss";
const SearchBar: React.FC = () => {
const sampledata: string[] = ["one", "two", "three", "four", "five", "six"]
const [searchValue, setSearchValue] = useState<string>("");
const [searchSelection, setSearchSelection] = useState<string>("");
const setSelectionValue = (value: string) => {
setSearchValue("");
setSearchSelection(value);
console.log(searchSelection);
}
return (
<div className="searchBar">
<div className="searchBarInput">
<input
type="text"
value={searchValue}
onChange={
(event) => {
setSearchValue(event.target.value);
console.log(searchSelection);
}
}
/>
</div>
<div className="searchResults">
{
searchValue === ""
|| sampledata.map((i) => i.toLowerCase().includes(searchValue.toLowerCase())
&& (<p key={i} className={"searchResult"} onClick={() => setSelectionValue(i)}>{i}</p>))
}
</div>
</div>
);
}
export default SearchBar;
|