Skip to content

Commit

Permalink
Adjust search results title when no results exist
Browse files Browse the repository at this point in the history
Update results title to display "0 Results" if no results are returned
on submitting the form.
Currently if the form is submitted without typing anything in, the
search results title says "Loading search index".
  • Loading branch information
danacotoran committed Mar 9, 2021
1 parent 8c1729d commit 88430c0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/assets/javascripts/_modules/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,14 @@
$searchForm.on('submit', function (e) {
e.preventDefault()
showResults()
$searchResults.find('.search-result__title a').first().focus()
var $firstResult = $searchResults.find('.search-result__title a').first()
if ($firstResult.length) {
$firstResult.focus()
} else {
// if there are no results, show the "0 results" state
results = []
updateTitle()
}
})

// Closing the search results, move focus back to the search input
Expand Down

0 comments on commit 88430c0

Please sign in to comment.