In a facet with the LinksWidget and an expanded hierarchy (with taxonomy terms), when I select only a children (not a first level item), the reset link is active (with the class is-active). I join a screenshot to demonstrate it.

The problem seems to be in \Drupal\facets\Plugin\facets\widget\LinksWidget, line 84

// Check if any other facet is in use.
$none_active = TRUE;
foreach ($results as $result) {
  if ($result->isActive()) {
     $none_active = FALSE;
         break;
    }
}
// Add an is-active class when no other facet is in use.
if ($none_active) {
    $item['#attributes'] = ['class' => ['is-active']];
}

This loop check only the first level, not for the childrens inside a Result.
To make it work with a hierarchy we will need something like

      foreach ($results as $result) {
        if ($result->isActive()) {
          $none_active = FALSE;
          break;
        }
        if ($childrens = $result->getChildren()) {
          foreach ($childrens as $children_result) {
            if ($children_result->isActive()) {
              $none_active = FALSE;
              break;
            }
          }
        }
      }

But this is not recursive, and not ready.
I will try to propose a patch soon (probably end of the week).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pierre-nono created an issue. See original summary.

borisson_’s picture

Title: Reset link is active when a children is selectionned » Reset link is active when only a child is selected

Have you found a solution for this? The approach you outlined in the issue seems like a good start.

Evaldas Užkuras’s picture

Status: Active » Needs review
FileSize
391 bytes
borisson_’s picture

This sounds like a good solution - I'm not sure if we need tests for this because it's a really simple fix.

c.altosax’s picture

This issue is still present in version 8.x-1.6. The patch in #3 works for me, and simple testing did not reveal any undesirable side-effects. I would love to see this fix merged in.

jannakha’s picture

Status: Needs review » Reviewed & tested by the community

patch works!

mkalkbrenner’s picture

Status: Reviewed & tested by the community » Fixed

Committed, thanks for your help!

Status: Fixed » Closed (fixed)

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