feat(search): hide "clear search" icon if input is empty (#388)

This commit is contained in:
Óscar
2024-09-19 16:00:34 +02:00
committed by GitHub
parent 0bebcd1c6d
commit 1ffe43f934
3 changed files with 7 additions and 2 deletions

View File

@@ -2675,6 +2675,7 @@ window.onload = function () {
results.innerHTML = '';
resultsContainer.style.display = 'none';
searchInput.removeAttribute('aria-activedescendant');
clearSearchButton.style.display = 'none';
}
// Close modal when clicking/tapping outside.
@@ -2941,10 +2942,13 @@ window.onload = function () {
searchInput.addEventListener(
'input',
async function () {
const searchTerm = this.value.trim();
const searchInput = this.value;
const searchTerm = searchInput.trim();
const searchIndex = await searchIndexPromise;
results.innerHTML = '';
// Use the raw input so the "clear" button appears even if there's only spaces.
clearSearchButton.style.display = searchInput.length > 0 ? 'block' : 'none';
resultsContainer.style.display = searchTerm.length > 0 ? 'block' : 'none';
// Perform the search and store the results.