Fix null value of .search-input selector

This commit is contained in:
Mimi 2020-07-11 21:15:29 +08:00
parent 46b4ad92b3
commit dca900aa7a

View File

@ -3,13 +3,12 @@
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
const algoliaSettings = CONFIG.algolia; const algoliaSettings = CONFIG.algolia;
const { indexName, appID, apiKey } = algoliaSettings; const { indexName, appID, apiKey } = algoliaSettings;
const input = document.querySelector('.search-input');
let search = instantsearch({ let search = instantsearch({
indexName, indexName,
searchClient : algoliasearch(appID, apiKey), searchClient : algoliasearch(appID, apiKey),
searchFunction: helper => { searchFunction: helper => {
if (input.value) { if (document.querySelector('.search-input').value) {
helper.search(); helper.search();
} }
} }
@ -98,7 +97,7 @@ document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('.popup-trigger').forEach(element => { document.querySelectorAll('.popup-trigger').forEach(element => {
element.addEventListener('click', () => { element.addEventListener('click', () => {
document.body.classList.add('search-active'); document.body.classList.add('search-active');
setTimeout(() => input.focus(), 500); setTimeout(() => document.querySelector('.search-input').focus(), 500);
}); });
}); });