Skip to content

Commit 0c774cf

Browse files
committed
feat: handle Escape keyboard actions
1 parent 2aa9e4a commit 0c774cf

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

static/search.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const MAX_ITEMS = 10;
22
const UP_ARROW = "ArrowUp";
33
const DOWN_ARROW = "ArrowDown";
44
const ENTER_KEY = "Enter";
5+
const ESCAPE_KEY = "Escape";
56

67
const searchInput = document.getElementById("search");
78
const searchResults = document.getElementById("search-results");
@@ -41,6 +42,14 @@ document.addEventListener("keydown", function (keyboardEvent) {
4142
if (target) target.click();
4243
break;
4344
}
45+
46+
case ESCAPE_KEY: {
47+
searchInput.value = "";
48+
searchResults.style.display = "none";
49+
searchInput.blur();
50+
break;
51+
}
52+
4453
}
4554
});
4655

0 commit comments

Comments
 (0)