From bccce36c9843f715ce29ab5659115c852766ecf1 Mon Sep 17 00:00:00 2001 From: Aditya Telange <21258296+adityatelange@users.noreply.github.com> Date: Fri, 18 Dec 2020 21:25:34 +0530 Subject: [PATCH] search: use kb nav only inside searchbox rm 'prevent mouseclick to change active element' --- assets/js/fastsearch.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/assets/js/fastsearch.js b/assets/js/fastsearch.js index 152d31c1..78248175 100644 --- a/assets/js/fastsearch.js +++ b/assets/js/fastsearch.js @@ -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 of first
  • @@ -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 - } -}