Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the performance of the hero search form. #177

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 8 additions & 8 deletions blocks/hero/search/home.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { decorateIcons } from '../../../scripts/aem.js';
import {
build as buildCountrySelect,
} from '../../shared/search-countries/search-countries.js';

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 +75,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 +113,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