Skip to content

Commit

Permalink
Debounce search inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
neobrain committed Oct 1, 2024
1 parent 09ff2db commit c35d3fd
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion assets/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
}

input.addEventListener('focus', init);
input.addEventListener('keyup', search);
input.addEventListener('input', search);

document.addEventListener('keypress', focusSearchFieldOnKeyPress);

Expand Down Expand Up @@ -79,7 +79,13 @@
.then(search);
}

let timeoutId;
function search() {
clearTimeout(timeoutId);
timeoutId = setTimeout(runSearch, 350);
}

function runSearch() {
while (results.firstChild) {
results.removeChild(results.firstChild);
}
Expand Down

0 comments on commit c35d3fd

Please sign in to comment.