Skip to content

Commit

Permalink
✨ feat: hide "clear search" icon when search is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
welpo committed Sep 19, 2024
1 parent 0bebcd1 commit 9525304
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions sass/parts/_search.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ $icon-size: 1.3rem;
}

.close-icon {
display: none;
position: absolute;
right: $icon-size;
margin-inline-start: 1rem;
Expand Down
6 changes: 5 additions & 1 deletion static/js/searchElasticlunr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Loading

0 comments on commit 9525304

Please sign in to comment.