Skip to content

Commit 9eeb37d

Browse files
author
matthewcsimpson
committed
hybrid filtering
1 parent 5a1ad78 commit 9eeb37d

3 files changed

Lines changed: 9 additions & 13 deletions

File tree

Dist/WebflowOnly/CMSFilter.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -780,20 +780,19 @@ class CMSFilter {
780780
/**
781781
* Categories whose checkbox availability ignores that facet’s own selections (hybrid mode).
782782
* Set on the form: wt-cmsfilter-hybrid-categories="bodytype" or "bodytype,colour"
783-
* If the attribute is omitted, defaults to ["bodytype"]. If present but empty, no categories self-exclude.
783+
* Omit or leave empty for no self-exclude categories (hybrid availability matches advanced for every facet).
784784
*/
785785
getHybridSelfExcludeCategories() {
786786
const raw = this.filterForm.getAttribute(
787787
"wt-cmsfilter-hybrid-categories",
788788
);
789-
if (raw === null) {
790-
return ["bodytype"];
789+
if (raw === null || raw.trim() === "") {
790+
return [];
791791
}
792-
const parsed = raw
792+
return raw
793793
.split(",")
794794
.map((s) => s.trim())
795795
.filter(Boolean);
796-
return parsed;
797796
}
798797

799798
UpdateAvailableFilters() {

__tests__/CMSFilter.test.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,13 @@ describe("CMSFilter", () => {
7474
}
7575

7676
/** make, bodytype, Category — hybrid (bodytype self-exclude) vs advanced */
77-
function buildHybridScenarioDOM(
78-
filteringMode = "hybrid",
79-
hybridCategoriesAttr,
80-
) {
77+
function buildHybridScenarioDOM(filteringMode = "hybrid", hybridCategoriesAttr) {
8178
const modeAttr = filteringMode
8279
? `wt-cmsfilter-filtering="${filteringMode}"`
8380
: "";
8481
const hybridAttr =
85-
hybridCategoriesAttr !== undefined
86-
? `wt-cmsfilter-hybrid-categories="${hybridCategoriesAttr}"`
82+
filteringMode === "hybrid"
83+
? ` wt-cmsfilter-hybrid-categories="${hybridCategoriesAttr ?? ""}"`
8784
: "";
8885
document.body.innerHTML = `
8986
<form wt-cmsfilter-element="filter-form" ${modeAttr} ${hybridAttr} wt-cmsfilter-debounce="0">
@@ -207,7 +204,7 @@ describe("CMSFilter", () => {
207204
});
208205

209206
test("hybrid mode narrows make like advanced but keeps all relevant body types visible for multi-select", () => {
210-
buildHybridScenarioDOM("hybrid");
207+
buildHybridScenarioDOM("hybrid", "bodytype");
211208
InitializeCMSFilter();
212209
const form = document.querySelector('[wt-cmsfilter-element="filter-form"]');
213210
const toyota = Array.from(

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`). **If omitted**, defaults to **`bodytype`**. **If present but empty**, every facet narrows like **`advanced`** (no hybrid self-exclude). 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.
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)