Merge pull request #509 from schnerring/flexsearch-bugfix
Fix flexsearch arrow key navigation error
This commit is contained in:
commit
6614ea5c8f
|
@ -34,23 +34,22 @@ Source:
|
||||||
document.addEventListener('keydown',suggestionFocus);
|
document.addEventListener('keydown',suggestionFocus);
|
||||||
|
|
||||||
function suggestionFocus(e) {
|
function suggestionFocus(e) {
|
||||||
|
const suggestionsHidden = suggestions.classList.contains('d-none');
|
||||||
|
if (suggestionsHidden) return;
|
||||||
|
|
||||||
const focusableSuggestions= suggestions.querySelectorAll('a');
|
const focusableSuggestions= [...suggestions.querySelectorAll('a')];
|
||||||
const focusable= [...focusableSuggestions];
|
if (focusableSuggestions.length === 0) return;
|
||||||
const index = focusable.indexOf(document.activeElement);
|
|
||||||
|
|
||||||
const keyDefault = suggestions.classList.contains('d-none');
|
const index = focusableSuggestions.indexOf(document.activeElement);
|
||||||
|
|
||||||
let nextIndex = 0;
|
if (e.key === "ArrowUp") {
|
||||||
|
|
||||||
if ((e.keyCode === 38) && (!keyDefault)) {
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
nextIndex= index > 0 ? index-1 : 0;
|
const nextIndex = index > 0 ? index - 1 : 0;
|
||||||
focusableSuggestions[nextIndex].focus();
|
focusableSuggestions[nextIndex].focus();
|
||||||
}
|
}
|
||||||
else if ((e.keyCode === 40) && (!keyDefault)) {
|
else if (e.key === "ArrowDown") {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
nextIndex= index+1 < focusable.length ? index+1 : index;
|
const nextIndex= index + 1 < focusableSuggestions.length ? index + 1 : index;
|
||||||
focusableSuggestions[nextIndex].focus();
|
focusableSuggestions[nextIndex].focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,11 +126,9 @@ Source:
|
||||||
|
|
||||||
//flatSearch now returns results for each index field. create a single list
|
//flatSearch now returns results for each index field. create a single list
|
||||||
const flatResults = {}; //keyed by href to dedupe results
|
const flatResults = {}; //keyed by href to dedupe results
|
||||||
results.forEach(result=>{
|
for (const result of results.flatMap(r => r.result)) {
|
||||||
result.result.forEach(r=>{
|
flatResults[result.doc.href] = result.doc;
|
||||||
flatResults[r.doc.href] = r.doc;
|
}
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
//construct a list of suggestions list
|
//construct a list of suggestions list
|
||||||
for(const href in flatResults) {
|
for(const href in flatResults) {
|
||||||
|
|
Loading…
Reference in New Issue