Skip to content

Commit 645ddbd

Browse files
committed
MAGE-986 Enable configurable selectable redirect with or without hits
1 parent 7d60b6b commit 645ddbd

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

Block/Configuration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ public function getConfiguration()
214214
'minimumCharacters' => $config->getAutocompleteMinimumCharacterLength(),
215215
'redirects' => [
216216
'enabled' => $config->isAutocompleteRedirectEnabled(),
217-
'hideSelectableItem' => $config->getAutocompleteRedirectMode() === AutocompleteRedirectMode::SUBMIT_ONLY,
217+
'showSelectableRedirect' => $config->getAutocompleteRedirectMode() !== AutocompleteRedirectMode::SUBMIT_ONLY,
218+
'showHitsWithRedirect' => $config->getAutocompleteRedirectMode() !== AutocompleteRedirectMode::SELECTABLE_REDIRECT,
218219
'openInNewWindow' => $config->isAutocompleteRedirectInNewWindowEnabled()
219220
]
220221
],

view/frontend/web/css/autocomplete.css

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/** Auto-completion menu */
22
html {
33
--autocomplete-muted-color: #969faf;
4+
--redirect-hit-element-height: 45px;
45
}
56

67
/********************
@@ -277,6 +278,11 @@ html {
277278
/********************
278279
REDIRECT HITS
279280
********************/
281+
282+
.aa-Panel .aa-PanelLayout:not(.show-selectable-redirect) section[data-autocomplete-source-id=redirectUrlPlugin] {
283+
display:none
284+
}
285+
280286
.aa-Panel .aa-PanelLayout section[data-autocomplete-source-id=redirectUrlPlugin] .aa-ItemWrapper,
281287
.aa-Panel .aa-PanelLayout section[data-autocomplete-source-id=redirectUrlPlugin] .aa-ItemWrapper .aa-ItemContent {
282288
display: flex;
@@ -305,7 +311,7 @@ html {
305311
}
306312

307313
/* Hide products when redirecting */
308-
.aa-Panel .aa-PanelLayout section[data-autocomplete-source-id=redirectUrlPlugin] ~ section[data-autocomplete-source-id=products] {
314+
.aa-Panel .aa-PanelLayout:not(.show-hits-with-redirect) section[data-autocomplete-source-id=redirectUrlPlugin] ~ section[data-autocomplete-source-id=products] {
309315
display: none;
310316
}
311317

@@ -380,11 +386,18 @@ html {
380386
/* Redirect section */
381387
.aa-Panel .aa-PanelLayout.with-grid section[data-autocomplete-source-id=redirectUrlPlugin] {
382388
grid-column: 2;
383-
grid-row: 1 / 999;
389+
grid-row: 1 / 999; /* Default mode is to replace the product section */
384390
border-left: 1px solid #BBB;
385391
z-index: 999;
386392
}
387393

394+
.aa-Panel .aa-PanelLayout.with-grid.show-hits-with-redirect section[data-autocomplete-source-id=redirectUrlPlugin] {
395+
z-index: 1000;
396+
/* Contain if showing with selectable redirect option */
397+
grid-row: 1;
398+
max-height: var(--redirect-hit-element-height);
399+
}
400+
388401
/* Products section */
389402
.aa-Panel .aa-PanelLayout.with-grid section[data-autocomplete-source-id=products] {
390403
grid-column: 2;
@@ -395,8 +408,9 @@ html {
395408
}
396409

397410
/* Redirect behaviors */
398-
.aa-Panel .aa-PanelLayout.with-grid section[data-autocomplete-source-id=redirectUrlPlugin] ~ section[data-autocomplete-source-id=products] {
399-
padding-top: 45px; /* Pad if showing with redirect option - set z-index as needed */
411+
.aa-Panel .aa-PanelLayout.with-grid.show-selectable-redirect section[data-autocomplete-source-id=redirectUrlPlugin] ~ section[data-autocomplete-source-id=products] {
412+
padding-top: var(--redirect-hit-element-height); /* Pad if showing with selectable redirect option */
413+
z-index: 999;
400414
}
401415

402416
/* Products grid */

view/frontend/web/js/autocomplete.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,15 @@ define([
184184
if (sections.length > 1) {
185185
classes.push('with-grid');
186186
}
187+
188+
if (algoliaConfig.autocomplete.redirects.showHitsWithRedirect) {
189+
classes.push('show-hits-with-redirect');
190+
}
191+
192+
if (algoliaConfig.autocomplete.redirects.showSelectableRedirect) {
193+
classes.push('show-selectable-redirect');
194+
}
195+
187196
render(
188197
html`<div class="${classes.join(' ')}">${sections}</div>`,
189198
root
@@ -799,7 +808,7 @@ define([
799808
onRedirect
800809
};
801810

802-
if (algoliaConfig.autocomplete.redirects.hideSelectableItem) {
811+
if (!algoliaConfig.autocomplete.redirects.showSelectableRedirect) {
803812
params.templates = {
804813
item({html, state}) {
805814
return html``;

0 commit comments

Comments
 (0)