Commit ad02257c authored by Clement Ho's avatar Clement Ho

Fix bug where clear search button would not toggle visible

parent d797b03b
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
const clearSearch = document.querySelector('.clear-search'); const clearSearch = document.querySelector('.clear-search');
input.addEventListener('input', this.tokenize.bind(this)); input.addEventListener('input', this.tokenize.bind(this));
input.addEventListener('input', this.toggleClearSearchButton);
input.addEventListener('keydown', this.checkForEnter.bind(this)); input.addEventListener('keydown', this.checkForEnter.bind(this));
clearSearch.addEventListener('click', this.clearSearch.bind(this)); clearSearch.addEventListener('click', this.clearSearch.bind(this));
...@@ -42,10 +43,8 @@ ...@@ -42,10 +43,8 @@
event.preventDefault(); event.preventDefault();
this.clearTokens(); this.clearTokens();
const input = document.querySelector('.filtered-search'); document.querySelector('.filtered-search').value = '';
input.value = ''; document.querySelector('.clear-search').classList.add('hidden');
event.target.classList.add('hidden');
} }
clearTokens() { clearTokens() {
...@@ -101,13 +100,20 @@ ...@@ -101,13 +100,20 @@
} }
} }
toggleClearSearchButton(event) {
const clearSearch = document.querySelector('.clear-search');
if (event.target.value) {
clearSearch.classList.remove('hidden');
} else {
clearSearch.classList.add('hidden');
}
}
tokenize(event) { tokenize(event) {
// Re-calculate tokens // Re-calculate tokens
this.clearTokens(); this.clearTokens();
// Enable clear button
document.querySelector('.clear-search').classList.remove('hidden');
const input = event.target.value; const input = event.target.value;
const inputs = input.split(' '); const inputs = input.split(' ');
let searchTerms = ''; let searchTerms = '';
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment