Problem/Motivation

Facets soft limits JS is breaking facets tree manipulations.

I built a custom module that interacts with the facet list to become collapsible if you have a hierarchical facet.
With the current implementation, the selector used in soft-limit.js breaks if some facet results are still hidden (which could make sense with a collapsible hierarchy).

Steps to reproduce

Consider the following hierarchical facet:

Tree:
- Val 1
- Val 2
-- Val 2.1
-- Val 2.2
--- Val 2.2.1
--- Val 2.2.2
- Val 3
- Val 4
-- Val 4.1
-- Val 4.1.2
- Val 5
- Val 6
- Val 7

With a soft limit of 5 items, Val 1, Val 2, Val 3, Val 4, Val 5 are visible by default. If you click on "view more", Val 6 and Val 7 are shown. If you click on "view less", the values 6 and 7 are hidden. This is consistent.

Now, if you add some JS logic to let the hierarchy be collapsible, the default output of the facet is:

- Val 1
- Val 2
- Val 3
- Val 4
- Val 5
- Val 6
- Val 7

The soft limit shows Val 1 to 5. If you click on "view more", you see Val 6 and Val 7 BUT if you click on "view less", Val 6 and Var 7 are not hidden due to the fact that Val 2.1, Val 2.2 and so on are still hidden.

This is due to the current selector used in the script.

Proposed resolution

Change the selector to apply to direct children li.

Issue fork facets-3208580

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Artusamak created an issue. See original summary.

pfrenssen made their first commit to this issue’s fork.

pfrenssen’s picture

Status: Active » Needs work

Rebased on 2.0.x. I made a backup of the original patch against an outdated version of 8.x-1.x available in a separate branch: 3208580-soft-limits-are-8.x-1.x.

pfrenssen’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
pfrenssen’s picture

Status: Needs work » Needs review
pfrenssen’s picture

@artusamak do you want to change the merge base from 8.x-1.x to 2.0.x in https://git.drupalcode.org/project/facets/-/merge_requests/17 ? Thanks!

artusamak’s picture

Done @pfrenssen

saidatom made their first commit to this issue’s fork.

idimopoulos made their first commit to this issue’s fork.

dimilias’s picture

Status: Needs review » Reviewed & tested by the community

This works fine for us. We are using the one which contains also the 0 limit addition. +1 RTBC.

stopopol’s picture

+1

saidatom’s picture

Version: 2.0.x-dev » 3.0.x-dev

smustgrave’s picture

Would be good to get this one in.

foxy-vikvik’s picture

StatusFileSize
new1.27 KB

For the "drupal/facets": "^3.0@beta"
In this case, button will be hide ONLY one level items

foxy-vikvik’s picture

StatusFileSize
new1.1 KB

For the "drupal/facets": "^3.0@beta"
This is working for all levels.

strykaizer made their first commit to this issue’s fork.

  • strykaizer committed 307103c1 on 3.0.x
    feat: #3208580 Soft limits are incompatible with a hierarchical (...
strykaizer’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +DevDaysAthens2026

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.