Skip to content

Commit c919320

Browse files
authored
Merge pull request #75 from matthewcsimpson/feature/hybrid-cms-filtering
Hybrid Filtering Update
2 parents dc09639 + 1004581 commit c919320

3 files changed

Lines changed: 50 additions & 1 deletion

File tree

Dist/WebflowOnly/CMSFilter.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,12 @@ class CMSFilter {
852852
}
853853
});
854854

855+
// Hybrid only: keep selected options visible so users can change or clear them
856+
// when other facets (e.g. make) rule them out of the current result set.
857+
if (filteringMode === "hybrid" && istoggle.checked) {
858+
isAvailable = true;
859+
}
860+
855861
// Restore original display style or hide
856862
if (isAvailable) {
857863
// Restore original display style

__tests__/CMSFilter.test.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,49 @@ describe("CMSFilter", () => {
239239
]);
240240
});
241241

242+
test("hybrid keeps checked body types visible when current make rules them out", () => {
243+
document.body.innerHTML = `
244+
<form wt-cmsfilter-element="filter-form" wt-cmsfilter-filtering="hybrid" wt-cmsfilter-hybrid-categories="bodytype" wt-cmsfilter-debounce="0">
245+
<label wt-cmsfilter-category="make"><input type="checkbox"><span>Toyota</span></label>
246+
<label wt-cmsfilter-category="make"><input type="checkbox"><span>Honda</span></label>
247+
<label wt-cmsfilter-category="bodytype"><input type="checkbox"><span>SUV</span></label>
248+
<label wt-cmsfilter-category="bodytype"><input type="checkbox"><span>Hatchback</span></label>
249+
<select wt-cmsfilter-element="sort-options"><option value="title-asc">A</option></select>
250+
<div wt-cmsfilter-element="results-count"></div>
251+
</form>
252+
<div wt-cmsfilter-element="list">
253+
<div data-make="Toyota" data-bodytype="SUV">T</div>
254+
<div data-make="Honda" data-bodytype="Hatchback">H</div>
255+
</div>
256+
<div wt-cmsfilter-element="empty" style="display:none;"></div>
257+
`;
258+
InitializeCMSFilter();
259+
const form = document.querySelector('[wt-cmsfilter-element="filter-form"]');
260+
const honda = Array.from(
261+
form.querySelectorAll('label[wt-cmsfilter-category="make"]'),
262+
).find((l) => l.textContent.includes("Honda"));
263+
const suv = Array.from(
264+
form.querySelectorAll('label[wt-cmsfilter-category="bodytype"]'),
265+
).find((l) => l.textContent.includes("SUV"));
266+
const hatch = Array.from(
267+
form.querySelectorAll('label[wt-cmsfilter-category="bodytype"]'),
268+
).find((l) => l.textContent.includes("Hatchback"));
269+
suv.querySelector("input").checked = true;
270+
hatch.querySelector("input").checked = true;
271+
honda.querySelector("input").checked = true;
272+
[suv, hatch, honda].forEach((el) =>
273+
el
274+
.querySelector("input")
275+
.dispatchEvent(new Event("change", { bubbles: true })),
276+
);
277+
const instance = window.webtricks[0].CMSFilter;
278+
instance.ApplyFilters();
279+
280+
expect(instance.filteredItems.length).toBe(1);
281+
expect(suv.style.display).not.toBe("none");
282+
expect(hatch.style.display).not.toBe("none");
283+
});
284+
242285
test("hybrid with empty wt-cmsfilter-hybrid-categories narrows all facets like advanced", () => {
243286
buildHybridScenarioDOM("hybrid", "");
244287
InitializeCMSFilter();

docs/WebflowOnly/CMSFilter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Add the script to your Webflow project and include the required attributes on yo
4949

5050
- `wt-cmsfilter-filtering="advanced"` - Enables advanced filtering mode with dynamic availability updates (every facet’s options narrow to the current result set; selecting one **make** hides other makes).
5151
- `wt-cmsfilter-filtering="hybrid"` - Like advanced, but selected categories (see below) keep **all** of their checkbox options that match the current filters **except** that category’s own selections (multi-select friendly). All **other** categories narrow from the current result set like **`advanced`**.
52-
- `wt-cmsfilter-hybrid-categories="bodytype"` - Comma-separated `wt-cmsfilter-category` names that use hybrid self-exclude behavior (e.g. `bodytype` or `bodytype,colour`). **Required** for any facet to use hybrid self-exclude; **omit or leave empty** if every facet should narrow like **`advanced`**. Requires matching `data-*` fields on list items for each listed category.
52+
- `wt-cmsfilter-hybrid-categories="bodytype"` - Comma-separated `wt-cmsfilter-category` names that use hybrid self-exclude behavior (e.g. `bodytype` or `bodytype,colour`). **Required** for any facet to use hybrid self-exclude; **omit or leave empty** if every facet should narrow like **`advanced`**. Requires matching `data-*` fields on list items for each listed category. **Checked** checkbox/radio options in **`hybrid`** stay visible so users can adjust or clear selections when another facet (e.g. make) no longer matches. **`advanced`** does not use this rule.
5353
- `wt-cmsfilter-trigger="button"` - Changes filter trigger to button submit instead of real-time
5454
- `wt-cmsfilter-class="classname"` - CSS class applied to active filter elements
5555
- `wt-cmsfilter-resetix2="true"` - Reset IX2 interactions on filtered items

0 commit comments

Comments
 (0)