Skip to content

Commit

Permalink
Allow searching for country names with diacritics (Shopify#3443)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamideha committed May 1, 2024
1 parent eefc111 commit ba52194
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions assets/localization-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,15 @@ if (!customElements.get('localization-form')) {
}
}

normalizeString(str) {
return str
.normalize('NFD')
.replace(/\p{Diacritic}/gu, '')
.toLowerCase();
}

filterCountries() {
const searchValue = this.elements.search.value.toLowerCase();
const searchValue = this.normalizeString(this.elements.search.value);
const popularCountries = this.querySelector('.popular-countries');
const allCountries = this.querySelectorAll('a');
let visibleCountries = allCountries.length;
Expand All @@ -151,7 +158,7 @@ if (!customElements.get('localization-form')) {
}

allCountries.forEach((item) => {
const countryName = item.querySelector('.country').textContent.toLowerCase();
const countryName = this.normalizeString(item.querySelector('.country').textContent);
if (countryName.indexOf(searchValue) > -1) {
item.parentElement.classList.remove('hidden');
visibleCountries++;
Expand Down

0 comments on commit ba52194

Please sign in to comment.