Skip to content

Commit 5c5fa96

Browse files
committed
Intercept / keystroke only if search modal not active
1 parent 5d9fd9a commit 5c5fa96

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/main.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ function handleBurgerClick(el) {
77

88
// search
99

10-
function showSearchModal() {
10+
function isSearchModalActive() {
1111
const modal = document.getElementById("search-modal");
12-
if (!modal.classList.contains("bulma-is-active")) {
12+
return modal.classList.contains("bulma-is-active");
13+
}
14+
15+
function showSearchModal() {
16+
if (!isSearchModalActive()) {
17+
const modal = document.getElementById("search-modal");
1318
modal.classList.add("bulma-is-active");
1419
const input = document.getElementById("search-input");
1520
input.value = "";
@@ -20,9 +25,10 @@ function showSearchModal() {
2025
}
2126

2227
function hideSearchModal() {
23-
const modal = document.getElementById("search-modal");
24-
if (modal.classList.contains("bulma-is-active"))
28+
if (isSearchModalActive()) {
29+
const modal = document.getElementById("search-modal");
2530
modal.classList.remove("bulma-is-active");
31+
}
2632
}
2733

2834
function renderHit(hit) {
@@ -62,11 +68,11 @@ function onSearchInput(event) {
6268
// Keyboard shortcuts: `/` to open, `Escape` to close
6369
window.addEventListener("keydown", (event) => {
6470
if (event.defaultPrevented) return;
65-
if (event.code == "Slash") {
71+
if (event.code == "Slash" && !isSearchModalActive()) {
6672
event.preventDefault();
6773
showSearchModal();
6874
}
69-
if (event.code == "Escape") {
75+
if (event.code == "Escape" && isSearchModalActive()) {
7076
event.preventDefault();
7177
hideSearchModal();
7278
}

0 commit comments

Comments
 (0)