diff --git a/lib/assets/javascripts/_modules/search.js b/lib/assets/javascripts/_modules/search.js index af8971fa..e4921088 100644 --- a/lib/assets/javascripts/_modules/search.js +++ b/lib/assets/javascripts/_modules/search.js @@ -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