Auto merge of #83028 - GuillaumeGomez:prevent-js-error-if-no-filter, r=Nemo157

Prevent JS error when there is no dependency or other crate documented (or --disable-per-crate-search has been used)

When there is only one crate, the dropdown is removed, creating an error (that you can see pretty easily on docs.rs for example).

r? `@jyn514`
This commit is contained in:
bors 2021-03-14 06:35:19 +00:00
commit 2caeeb0527
1 changed files with 5 additions and 1 deletions

View File

@ -2948,7 +2948,11 @@ function defocusSearchBar() {
search_input.removeAttribute('disabled');
var crateSearchDropDown = document.getElementById("crate-search");
crateSearchDropDown.addEventListener("focus", loadSearch);
// `crateSearchDropDown` can be null in case there is only crate because in that case, the
// crate filter dropdown is removed.
if (crateSearchDropDown) {
crateSearchDropDown.addEventListener("focus", loadSearch);
}
var params = getQueryStringParams();
if (params.search !== undefined) {
loadSearch();