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

fix: Bad display in the prices filters while uncheck one of the filters #539

Merged
merged 1 commit into from
Aug 10, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
{elseif $facet.widgetType == 'slider'}
{block name='facet_item_slider'}
{foreach from=$facet.filters item="filter"}
<div class="accordion-body faceted-filter px-3 js-faceted-filter-slider">
<div class="accordion-body faceted-filter px-0 js-faceted-filter-slider">
<div
class="faceted-slider js-faceted-slider-container"
data-slider-min="{$facet.properties.min}"
Expand All @@ -191,6 +191,7 @@
data-slider-direction="{$language.is_rtl}"
>
</div>
<div class="js-faceted-values"></div>
<input
type="hidden"
class="form-range-start js-faceted-slider js-faceted-slider-start"
Expand Down
23 changes: 23 additions & 0 deletions src/js/modules/facetedsearch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const initSliders = () => {
// Get all slider configurations found in the DOM
document.querySelectorAll(Theme.selectors.facetedsearch.filterSlider).forEach((filter: HTMLElement) => {
const container = <target>filter.querySelector(Theme.selectors.facetedsearch.rangeContainer);
const facetedValues = document.querySelector('.js-faceted-values') as HTMLElement;

// Init basic slider data
let unitPosition = 'suffix';
Expand Down Expand Up @@ -88,9 +89,20 @@ export const initSliders = () => {
},
});

// Remove tooltips:
initiatedSlider.removeTooltips();

initiatedSlider.on('set', (values, handle, unencoded, tap, positions, instance) => {
filterHandler(values, instance);
});

initiatedSlider.on('update', (values) => {
const formattedValues: string[] = values.map((value) => (
unitPosition === 'suffix' ? `${value}${unitSymbol}` : `${unitSymbol}${value}`),
);

facetedValues.innerHTML = formattedValues.join(' - ');
});
} else {
container.noUiSlider.updateOptions({
start: sliderValues ?? [min, max],
Expand All @@ -101,9 +113,20 @@ export const initSliders = () => {
},
}, true);

// Remove tooltips:
container.noUiSlider.removeTooltips();

container.noUiSlider.on('set', (values, handle, unencoded, tap, positions, instance) => {
filterHandler(values, instance);
});

container.noUiSlider.on('update', (values) => {
const formattedValues: string[] = values.map((value) => (
unitPosition === 'suffix' ? `${value}${unitSymbol}` : `${unitSymbol}${value}`),
);

facetedValues.innerHTML = formattedValues.join(' - ');
});
}
});
};
Expand Down
7 changes: 6 additions & 1 deletion src/scss/core/modules/_facetedsearch.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ $component-name: search-filters;
}

.noUi-horizontal {
margin-bottom: 2rem;
margin-bottom: 1rem;

.noUi-handle {
display: flex;
Expand All @@ -17,6 +17,11 @@ $component-name: search-filters;
}
}

.js-faceted-values{
font-size: 0.875rem;
color: var(--bs-gray-600);
}

.facet-dropdown {
cursor: pointer;
}
Expand Down