mirror of
https://github.com/adityatelange/hugo-PaperMod.git
synced 2023-12-21 10:22:58 +01:00
search: use kb nav only inside searchbox
rm 'prevent mouseclick to change active element'
This commit is contained in:
parent
a150c3449a
commit
bccce36c98
@ -76,8 +76,9 @@ document.getElementById("searchInput").onkeyup = function (e) {
|
|||||||
document.onkeydown = function (e) {
|
document.onkeydown = function (e) {
|
||||||
let key = e.key;
|
let key = e.key;
|
||||||
let ae = document.activeElement;
|
let ae = document.activeElement;
|
||||||
|
let inbox = document.getElementById("searchbox").contains(ae)
|
||||||
|
|
||||||
if (key === "ArrowDown" && resultsAvailable) {
|
if (key === "ArrowDown" && resultsAvailable && inbox) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (ae == sInput) {
|
if (ae == sInput) {
|
||||||
// if the currently focused element is the search input, focus the <a> of first <li>
|
// 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();
|
ae.parentElement.nextSibling.lastChild.focus();
|
||||||
activeToggle(); // add active class
|
activeToggle(); // add active class
|
||||||
}
|
}
|
||||||
} else if (key === "ArrowUp" && resultsAvailable) {
|
} else if (key === "ArrowUp" && resultsAvailable && inbox) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (ae == sInput) {
|
if (ae == sInput) {
|
||||||
// if the currently focused element is input box, do nothing
|
// if the currently focused element is input box, do nothing
|
||||||
@ -106,7 +107,7 @@ document.onkeydown = function (e) {
|
|||||||
ae.parentElement.previousSibling.lastChild.focus();
|
ae.parentElement.previousSibling.lastChild.focus();
|
||||||
activeToggle(); // add active class
|
activeToggle(); // add active class
|
||||||
}
|
}
|
||||||
} else if (key === "ArrowRight" && resultsAvailable) {
|
} else if (key === "ArrowRight" && resultsAvailable && inbox) {
|
||||||
ae.click(); // click on active link
|
ae.click(); // click on active link
|
||||||
} else if (key === "Escape") {
|
} else if (key === "Escape") {
|
||||||
resultsAvailable = false;
|
resultsAvailable = false;
|
||||||
@ -114,9 +115,3 @@ document.onkeydown = function (e) {
|
|||||||
sInput.focus(); // shift focus to input box
|
sInput.focus(); // shift focus to input box
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.onmousedown = function (e) {
|
|
||||||
if (e.type === "mousedown") {
|
|
||||||
e.preventDefault(); // prevent mousedown to change focus
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user