Hiding of the suggestions drop-down list

- Suggestions disappear when search is performed as a result of pressing
  enter in the search box.
This commit is contained in:
Veloman Yunkan
2022-08-10 13:24:51 +04:00
parent 2083c390b5
commit 9a193735fb
2 changed files with 13 additions and 2 deletions

View File

@ -125,7 +125,17 @@ function getSearchPattern() {
return null;
}
let autoCompleteJS = null;
function closeSuggestions() {
if ( autoCompleteJS ) {
autoCompleteJS.close();
}
}
function updateSearchBoxForLocationChange() {
closeSuggestions();
document.getElementById("kiwixsearchbox").value = getSearchPattern();
}
@ -217,7 +227,7 @@ document.addEventListener('DOMContentLoaded', function () {
const kiwixSearchBox = document.querySelector('#kiwixsearchbox');
const kiwixSearchFormWrapper = document.querySelector('.kiwix_searchform');
const autoCompleteJS = new autoComplete(
autoCompleteJS = new autoComplete(
{
selector: "#kiwixsearchbox",
placeHolder: kiwixSearchBox.title,
@ -263,6 +273,7 @@ document.addEventListener('DOMContentLoaded', function () {
);
document.querySelector('#kiwixsearchform').addEventListener('submit', function(event) {
closeSuggestions();
try {
const selectedElem = document.querySelector('.autoComplete_selected > a');
if (selectedElem) {