Skip to content

Commit

Permalink
Merge pull request #539 from tblivet/issue-534
Browse files Browse the repository at this point in the history
fix: Bad display in the prices filters while uncheck one of the filters
  • Loading branch information
jolelievre authored Aug 10, 2023
2 parents 158dbe5 + 81e8204 commit d74b09d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
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

0 comments on commit d74b09d

Please sign in to comment.