diff --git a/assets/js/theme.js b/assets/js/theme.js index 51d359176..ff5deb477 100644 --- a/assets/js/theme.js +++ b/assets/js/theme.js @@ -189,7 +189,10 @@ function initSearch () { window._searchMobileOnce = true // Turn on the mask when clicking on the search button searchInput.addEventListener('focus', () => { - loadScript('autocomplete-script', '/lib/autocomplete/autocomplete.min.js', () => initAutosearch()) + loadScript('autocomplete-script', '/lib/autocomplete/autocomplete.min.js', () => { + initAutosearch(); + searchInput.focus(); + }) if (window.config?.search?.type === 'algolia') { loadScript('algolia-script', '/lib/algoliasearch/algoliasearch-lite.umd.min.js', null) } else { @@ -197,6 +200,7 @@ function initSearch () { } document.body.classList.add('blur') header.classList.add('open') + searchInput.focus() }) // Turn off the everything when clicking on the cancel button document.getElementById('search-cancel-mobile').addEventListener('click', () => { @@ -236,6 +240,7 @@ function initSearch () { } document.body.classList.add('blur') header.classList.add('open') + searchInput.focus() }) // Clear the search box when clicking on the clear button searchClear.addEventListener('click', () => {