Skip to content

Commit

Permalink
feat: lancer la recherche en appuyant sur les 2 entrées du clavier
Browse files Browse the repository at this point in the history
  • Loading branch information
ocruze committed May 28, 2024
1 parent 7dcd38f commit 5b90748
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions public/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ const SEARCH_PARAM = "term";

const search = () => {
const searchResultsUrl = new URL(SEARCH_RESULTS_URL, window.location.origin);
searchResultsUrl.searchParams.append(SEARCH_PARAM, searchInput.value);
window.location.href = searchResultsUrl;

if (searchInput.value?.length > 0) {
searchResultsUrl.searchParams.append(SEARCH_PARAM, searchInput.value);
window.location.href = searchResultsUrl;
}
};

searchInput.addEventListener("keydown", async (event) => {
if (event.code === "Enter") {
if (event.code === "Enter" || event.code === "NumpadEnter") {
await search();
}
});
Expand Down

0 comments on commit 5b90748

Please sign in to comment.