Close docs search box when an entry is selected

This comes up when clicking a link that changes
the fragment only, meaning the page doesn't transition
and the box doesn't get closed that way.
This commit is contained in:
Richard Feldman 2025-01-14 20:15:50 -05:00
parent ec2b8f9676
commit c5d07c07ec
No known key found for this signature in database

View file

@ -34,9 +34,10 @@ const setupSearch = () => {
let searchForm = document.getElementById("module-search-form");
let topSearchResultListItem = undefined;
// Hide the results whenever anyone clicks outside the search results.
// Hide the results whenever anyone clicks outside the search results,
// or on a specific search result.
window.addEventListener("click", function (event) {
if (!searchForm?.contains(event.target)) {
if (!searchForm?.contains(event.target) || event.target.closest("#search-type-ahead a")) {
searchTypeAhead.classList.add("hidden");
}
});
@ -101,6 +102,12 @@ const setupSearch = () => {
break;
}
case "Enter": {
// In case this is just an anchor link (which will move the scroll bar but not
// reload the page), hide the search bar.
searchTypeAhead.classList.add("hidden");
break;
}
}
}