search: use kb nav only inside searchbox

rm 'prevent mouseclick to change active element'
This commit is contained in:
Aditya Telange 2020-12-18 21:25:34 +05:30
parent a150c3449a
commit bccce36c98
No known key found for this signature in database
GPG Key ID: 82E844EF3DA99E77

View File

@ -76,8 +76,9 @@ document.getElementById("searchInput").onkeyup = function (e) {
document.onkeydown = function (e) {
let key = e.key;
let ae = document.activeElement;
let inbox = document.getElementById("searchbox").contains(ae)
if (key === "ArrowDown" && resultsAvailable) {
if (key === "ArrowDown" && resultsAvailable && inbox) {
e.preventDefault();
if (ae == sInput) {
// if the currently focused element is the search input, focus the <a> of first <li>
@ -92,7 +93,7 @@ document.onkeydown = function (e) {
ae.parentElement.nextSibling.lastChild.focus();
activeToggle(); // add active class
}
} else if (key === "ArrowUp" && resultsAvailable) {
} else if (key === "ArrowUp" && resultsAvailable && inbox) {
e.preventDefault();
if (ae == sInput) {
// if the currently focused element is input box, do nothing
@ -106,7 +107,7 @@ document.onkeydown = function (e) {
ae.parentElement.previousSibling.lastChild.focus();
activeToggle(); // add active class
}
} else if (key === "ArrowRight" && resultsAvailable) {
} else if (key === "ArrowRight" && resultsAvailable && inbox) {
ae.click(); // click on active link
} else if (key === "Escape") {
resultsAvailable = false;
@ -114,9 +115,3 @@ document.onkeydown = function (e) {
sInput.focus(); // shift focus to input box
}
}
document.onmousedown = function (e) {
if (e.type === "mousedown") {
e.preventDefault(); // prevent mousedown to change focus
}
}