-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.js
37 lines (32 loc) · 1.13 KB
/
search.js
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
const inputElement = document.querySelector("#search-input");
const search_icon = document.querySelector("#search-close-icon");
const sort_wrapper = document.querySelector(".sort-wrapper");
inputElement.addEventListener("input", () => {
handleInputChange(inputElement);
});
search_icon.addEventListener("click", handleSearchCloseOnClick);
sort_wrapper.addEventListener("click", handleSortIconOnClick);
function handleInputChange(inputElement) {
const inputValue = inputElement.value;
if (inputValue !== "") {
document
.querySelector("#search-close-icon")
.classList.add("search-close-icon-visible");
} else {
document
.querySelector("#search-close-icon")
.classList.remove("search-close-icon-visible");
}
}
function handleSearchCloseOnClick() {
document.querySelector("#search-input").value = "";
document
.querySelector("#search-close-icon")
.classList.remove("search-close-icon-visible");
}
function handleSortIconOnClick() {
document
.querySelector(".filter-wrapper")
.classList.toggle("filter-wrapper-open");
document.querySelector("body").classList.toggle("filter-wrapper-overlay");
}