diff --git a/packages/docusaurus-theme-search-algolia/src/pages/search/index.js b/packages/docusaurus-theme-search-algolia/src/pages/search/index.js
index bb96bcd407..4ff0becb1a 100644
--- a/packages/docusaurus-theme-search-algolia/src/pages/search/index.js
+++ b/packages/docusaurus-theme-search-algolia/src/pages/search/index.js
@@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/
+/* eslint-disable jsx-a11y/no-autofocus */
+
import React, {useEffect, useState, useReducer, useRef} from 'react';
import algoliaSearch from 'algoliasearch/lite';
@@ -20,6 +22,10 @@ import Layout from '@theme/Layout';
import styles from './styles.module.css';
+function pluralize(count, word) {
+ return count > 1 ? `${word}s` : word;
+}
+
function Search() {
const {
siteConfig: {
@@ -237,6 +243,7 @@ function Search() {
onChange={handleSearchInputChange}
value={searchQuery}
autoComplete="off"
+ autoFocus
/>
@@ -266,7 +273,10 @@ function Search() {
{!!searchResultState.totalResults && (
- {searchResultState.totalResults} documents found
+
+ {searchResultState.totalResults}{' '}
+ {pluralize(searchResultState.totalResults, 'document')} found
+
)}
diff --git a/packages/docusaurus-theme-search-algolia/src/theme/SearchBar/index.js b/packages/docusaurus-theme-search-algolia/src/theme/SearchBar/index.js
index ddac0c6e16..8e9ff2d1d6 100644
--- a/packages/docusaurus-theme-search-algolia/src/theme/SearchBar/index.js
+++ b/packages/docusaurus-theme-search-algolia/src/theme/SearchBar/index.js
@@ -37,6 +37,8 @@ const Search = (props) => {
// Override algolia's default selection event, allowing us to do client-side
// navigation and avoiding a full page refresh.
handleSelected: (_input, _event, suggestion) => {
+ _event.stopPropagation();
+
// Use an anchor tag to parse the absolute url into a relative url
// Alternatively, we can use new URL(suggestion.url) but it's not supported in IE.
const a = document.createElement('a');
@@ -93,7 +95,7 @@ const Search = (props) => {
});
const handleSearchInputPressEnter = useCallback((e) => {
- if (e.key === 'Enter') {
+ if (!e.defaultPrevented && e.key === 'Enter') {
navigateToSearchPage(e.target.value);
}
});