Skip to content

Commit

Permalink
If flexsearch returns no results, display message
Browse files Browse the repository at this point in the history
  • Loading branch information
schnerring committed Oct 15, 2021
1 parent 1710b80 commit af6c51f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 9 additions & 0 deletions assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ Source:
suggestions.innerHTML = "";
suggestions.classList.remove('d-none');

// inform user that no results were found
if (flatResults.size === 0) {
const noResultsMessage = document.createElement('div')
noResultsMessage.innerHTML = `No results for "<strong>${searchQuery}</strong>"`
noResultsMessage.classList.add("suggestion__no-results");
suggestions.appendChild(noResultsMessage);
return;
}

// construct a list of suggestions
for(const [href, doc] of flatResults) {
const entry = document.createElement('div');
Expand Down
11 changes: 8 additions & 3 deletions assets/scss/components/_search.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@
z-index: $zindex-dropdown;
}

#suggestions a,
.suggestion__no-results {
padding: 0.75rem;
margin: 0 0.5rem;
}

#suggestions a {
display: block;
text-decoration: none;
padding: 0.75rem;
margin: 0 0.5rem;
}

#suggestions a:focus {
Expand Down Expand Up @@ -48,7 +52,8 @@
color: $black;
}

.suggestion__description {
.suggestion__description,
.suggestion__no-results {
color: $gray-700;
}

Expand Down

0 comments on commit af6c51f

Please sign in to comment.