Skip to content

Commit

Permalink
Merge pull request #2070 from 10up/feature/1610
Browse files Browse the repository at this point in the history
Add a class to the search form when autosuggestions are loading. Addresses #1610.
  • Loading branch information
brandwaffle authored Feb 22, 2021
2 parents 1fe2292 + d7619b3 commit 93ad393
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
20 changes: 20 additions & 0 deletions assets/js/autosuggest.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,22 @@ function checkForOrderedPosts(hits, searchTerm) {
return hits;
}

/**
* Add class to the form element while suggestions are being loaded
*
* @param {boolean} isLoading - whether suggestions are loading
* @param {Node} input - search input field
*/
function setFormIsLoading(isLoading, input) {
const form = input.closest('form');

if (isLoading) {
form.classList.add('is-loading');
} else {
form.classList.remove('is-loading');
}
}

/**
* init method called if the epas endpoint is defined
*/
Expand Down Expand Up @@ -549,6 +565,8 @@ function init() {
}

if (searchText.length >= 2) {
setFormIsLoading(true, input);

const query = buildSearchQuery(searchText, placeholder, queryJSON);

// fetch the results
Expand All @@ -566,6 +584,8 @@ function init() {
} else {
hideAutosuggestBox();
}

setFormIsLoading(false, input);
} else if (searchText.length === 0) {
hideAutosuggestBox();
}
Expand Down
2 changes: 1 addition & 1 deletion dist/js/autosuggest-script.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/autosuggest-script.min.js.map

Large diffs are not rendered by default.

0 comments on commit 93ad393

Please sign in to comment.