Skip to content

Commit bccce36

Browse files
committed
search: use kb nav only inside searchbox
rm 'prevent mouseclick to change active element'
1 parent a150c34 commit bccce36

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

assets/js/fastsearch.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ document.getElementById("searchInput").onkeyup = function (e) {
7676
document.onkeydown = function (e) {
7777
let key = e.key;
7878
let ae = document.activeElement;
79+
let inbox = document.getElementById("searchbox").contains(ae)
7980

80-
if (key === "ArrowDown" && resultsAvailable) {
81+
if (key === "ArrowDown" && resultsAvailable && inbox) {
8182
e.preventDefault();
8283
if (ae == sInput) {
8384
// if the currently focused element is the search input, focus the <a> of first <li>
@@ -92,7 +93,7 @@ document.onkeydown = function (e) {
9293
ae.parentElement.nextSibling.lastChild.focus();
9394
activeToggle(); // add active class
9495
}
95-
} else if (key === "ArrowUp" && resultsAvailable) {
96+
} else if (key === "ArrowUp" && resultsAvailable && inbox) {
9697
e.preventDefault();
9798
if (ae == sInput) {
9899
// if the currently focused element is input box, do nothing
@@ -106,17 +107,11 @@ document.onkeydown = function (e) {
106107
ae.parentElement.previousSibling.lastChild.focus();
107108
activeToggle(); // add active class
108109
}
109-
} else if (key === "ArrowRight" && resultsAvailable) {
110+
} else if (key === "ArrowRight" && resultsAvailable && inbox) {
110111
ae.click(); // click on active link
111112
} else if (key === "Escape") {
112113
resultsAvailable = false;
113114
document.getElementById("searchResults").innerHTML = sInput.value = ''; // clear inputbox and searchResults
114115
sInput.focus(); // shift focus to input box
115116
}
116117
}
117-
118-
document.onmousedown = function (e) {
119-
if (e.type === "mousedown") {
120-
e.preventDefault(); // prevent mousedown to change focus
121-
}
122-
}

0 commit comments

Comments
 (0)