fix(search): 🐛 do not add empty term to search history

This commit is contained in:
alistair3149 2023-08-22 14:20:54 -07:00
parent 2ed6b71165
commit bd41516190
No known key found for this signature in database
GPG key ID: 16076C01E5C88864

View file

@ -194,14 +194,15 @@ const typeahead = {
const item = event.target.closest( '.citizen-typeahead__item' );
if ( item instanceof HTMLElement ) {
let historyLabel;
// User click on a suggestion -> save the matched title > title
if ( item.classList.contains( 'citizen-typeahead__item-page' ) ) {
historyLabel = item.querySelector( '.citizen-typeahead__label' ).innerText ?? item.querySelector( '.citizen-typeahead__title' ).innerText;
historyLabel = item.querySelector( '.citizen-typeahead__label' ).innerText || item.querySelector( '.citizen-typeahead__title' ).innerText;
} else {
historyLabel = searchQuery.value;
}
searchHistory.add( historyLabel );
if ( historyLabel ) {
searchHistory.add( historyLabel );
}
}
}
},