Skip to content

Commit

Permalink
Improve the performance of the hero search form.
Browse files Browse the repository at this point in the history
  • Loading branch information
bstopp committed Nov 29, 2023
1 parent 19453db commit 0268be9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
7 changes: 6 additions & 1 deletion blocks/hero/search/home.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
display: none;
}

.hero.block .content .homes .search-bar .search-country-select-parent {
position: relative;
width: 80px;
}

.hero.block .content .homes .search-bar .suggester-input {
flex: 1;
}
Expand Down Expand Up @@ -45,7 +50,7 @@
justify-content: center;
}

.hero.block .content .homes .search-bar .filter span.icon svg {
.hero.block .content .homes .search-bar .filter span.icon img {
height: 22px;
width: 22px;
color: var(--black);
Expand Down
15 changes: 8 additions & 7 deletions blocks/hero/search/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {

function observeForm() {
const script = document.createElement('script');
script.type = 'text/partytown';
script.type = 'module';
script.innerHTML = `
const script = document.createElement('script');
script.type = 'module';
Expand Down Expand Up @@ -76,6 +76,7 @@ async function buildForm() {
</div>
<div class="search-bar" role="search">
<div class="search-suggester">
<div class="search-country-select-parent"></div>
<div class="suggester-input">
<input type="text" placeholder="${getPlaceholder()}" aria-label="${getPlaceholder()}" name="keyword">
<input type="hidden" name="query">
Expand Down Expand Up @@ -113,12 +114,12 @@ async function buildForm() {
input.setAttribute('aria-label', placeholder);
};

const countrySelect = await buildCountrySelect(changeCountry);
if (countrySelect) {
form.querySelector('.search-suggester').prepend(countrySelect);
}
decorateIcons(form);
observeForm();
buildCountrySelect(changeCountry).then((select) => {
if (select) {
form.querySelector('.search-country-select-parent').append(select);
}
});
window.setTimeout(observeForm, 3000);
return form;
}

Expand Down
2 changes: 1 addition & 1 deletion blocks/shared/search-countries/search-countries.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export async function build(...callbacks) {
selected.classList.add('selected');
selected.setAttribute('aria-haspopup', 'listbox');
selected.setAttribute('aria-expanded', 'false');
selected.setAttribute('aria-label', 'Select Country');
selected.setAttribute('aria-label', `${first.value} - Select Country`);
selected.setAttribute('role', 'button');
selected.setAttribute('tabIndex', '0');
selected.innerHTML = imgHTML(first.value);
Expand Down

0 comments on commit 0268be9

Please sign in to comment.