diff --git a/packages/web-components/src/search/components/product-search-overlay-results.ts b/packages/web-components/src/search/components/product-search-overlay-results.ts
index 585855d..53914dd 100644
--- a/packages/web-components/src/search/components/product-search-overlay-results.ts
+++ b/packages/web-components/src/search/components/product-search-overlay-results.ts
@@ -6,7 +6,7 @@ import { SearchResult } from '../product-search-overlay';
export class ProductSearchOverlayResults extends LitElement {
@property()
- setSearchTerm = (term: string) => {};
+ setSearchTerm = (term: string) => { };
@property()
noResultsMessage: string | null = null;
@@ -16,9 +16,9 @@ export class ProductSearchOverlayResults extends LitElement {
@property({ type: Number })
selectedIndex = -1;
-
+
@property()
- setResultOverlayHovered = (hovered: boolean) => {};
+ setResultOverlayHovered = (hovered: boolean) => { };
connectedCallback(): void {
super.connectedCallback();
@@ -35,7 +35,7 @@ export class ProductSearchOverlayResults extends LitElement {
` : html`
${this.results.map((result, index) => {
- return html`
+ return html`
${result.searchTermPrediction ?
html`
@@ -45,15 +45,15 @@ export class ProductSearchOverlayResults extends LitElement {
- ` :
+ ` :
html`
`}
`;
- },
- )}
+ },
+ )}
`}
`;
@@ -90,7 +90,7 @@ export class ProductSearchOverlayResults extends LitElement {
}
.rw-products-container {
- display :flex;
+ display: flex;
flex-direction: column;
}
@@ -102,7 +102,7 @@ export class ProductSearchOverlayResults extends LitElement {
}
.rw-selected-result[selected] {
- background-color: whitesmoke;
+ background-color: var(--relewise-hover-color, whitesmoke);
}
.rw-prediction-item-container:hover {
diff --git a/packages/web-components/src/search/product-search-overlay.ts b/packages/web-components/src/search/product-search-overlay.ts
index 90e2fb8..86da186 100644
--- a/packages/web-components/src/search/product-search-overlay.ts
+++ b/packages/web-components/src/search/product-search-overlay.ts
@@ -12,7 +12,7 @@ export class SearchResult {
}
export class ProductSearchOverlay extends LitElement {
-
+
@property({ attribute: 'displayed-at-location' })
displayedAtLocation?: string = undefined;
@@ -27,8 +27,8 @@ export class ProductSearchOverlay extends LitElement {
@state()
term: string = '';
-
- @state()
+
+ @state()
selectedIndex = -1;
@state()
@@ -41,7 +41,7 @@ export class ProductSearchOverlay extends LitElement {
hasCompletedSearchRequest: boolean = false;
private debounceTimeoutHandlerId: ReturnType | null = null;
-
+
async connectedCallback() {
if (!this.displayedAtLocation) {
console.error('No displayedAtLocation defined!');
@@ -98,8 +98,23 @@ export class ProductSearchOverlay extends LitElement {
this.setSearchTerm(result.searchTermPrediction.term ?? '');
}
- if (result.product && result.product.data && 'Url' in result.product.data) {
- window.location.href = result.product.data['Url'].value ?? '';
+ if (result.product) {
+ const selectedProduct = this.shadowRoot!
+ .querySelector('relewise-product-search-overlay-results')
+ ?.shadowRoot
+ ?.querySelector('.rw-selected-result[selected]');
+
+ if (selectedProduct) {
+ const productLink = selectedProduct
+ .querySelector('relewise-product-search-overlay-product')
+ ?.shadowRoot
+ ?.querySelector('a')
+ ?.getAttribute('href');
+
+ if (productLink) {
+ window.location.href = productLink;
+ }
+ }
}
}
@@ -130,7 +145,7 @@ export class ProductSearchOverlay extends LitElement {
.addEntityType('Product')
.build());
}
-
+
const response = await searcher.batch(requestBuilder.build());
if (response && response.responses) {
@@ -158,7 +173,7 @@ export class ProductSearchOverlay extends LitElement {
return html`
this.setSearchTerm(term)}
+ .setSearchTerm=${(term: string) => this.setSearchTerm(term)}
.setSearchBarInFocus=${(inFocus: boolean) => this.searchBarInFocus = inFocus}
.placeholder=${localization?.searchBar?.placeholder ?? 'Search'}
.handleKeyEvent=${(e: KeyboardEvent) => this.handleKeyDown(e)}
@@ -166,13 +181,13 @@ export class ProductSearchOverlay extends LitElement {
${(this.searchBarInFocus &&
this.hasCompletedSearchRequest &&
this.term) ||
- this.resultBoxIsHovered ?
+ this.resultBoxIsHovered ?
html` this.setSearchTerm(term)}
+ .setSearchTerm=${(term: string) => this.setSearchTerm(term)}
.noResultsMessage=${localization?.searchResults?.noResults ?? 'No products found'}
- .setResultOverlayHovered=${(hovered: boolean) => this.resultBoxIsHovered = hovered }>
+ .setResultOverlayHovered=${(hovered: boolean) => this.resultBoxIsHovered = hovered}>
` : nothing
}
`;