Facets with 'Empty facet behavior' set to >> Do not display facet

Created on 8 February 2024, 10 months ago
Updated 6 September 2024, 3 months ago

Problem/Motivation

I have a number of facets that all work exactly as designed except for the fact the setting ...

... does not appear to work very well.

In each case, at least the block Title is present and, even though the wrapping facet div is clearly marked with the class facet-empty facet-hidden confirming what I have asked for, the facets block is not strictly 'empty' and so the space is allocated for it on the rendered page...

<div class="facet-inactive hidden block-facet--links block block-facets block-facet-blockcontent-type"
  id="block-bit-by-bit-type">

  <h2>Content type</h2>

  <div data-drupal-facet-id="content_type" class="facet-empty facet-hidden">
    <div class="facets-widget-links">
    </div>
  </div>

</div>

Does anyone have any ideas or guidance as to whether my expectations are wrong or on how to combat this (maybe with some nifty Twig)?

Thanks all

๐Ÿ› Bug report
Status

Needs review

Version

2.0

Component

User interface

Created by

๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom SirClickALot Somerset

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @SirClickALot
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Jeya sundhar Coimbatore

    Jeya sundhar โ†’ made their first commit to this issueโ€™s fork.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Jeya sundhar Coimbatore

    This Issue fixed in 3.0.x-dev

  • Pipeline finished with Failed
    7 months ago
    Total: 718s
    #148271
  • Status changed to Needs review 7 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Jeya sundhar Coimbatore
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States devkinetic

    I haven't dug into this too much, is the container there for some type of ajax purpose? I also see this is already handled differently in 3.x where it returns an empty array, perhaps that would be the preferrable solution. I went ahead and applied the patch, so far in testing things are working, but I do have Bigpipe disabled for facets, if that's a potential factor.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium ludo.r Brussels

    Just tested patch #6, it indeed returns an empty block.

    However, I removed the patch, as I see that the default behavior of facets module is to show the block but add the hidden class.
    So I think there must be a reason for that.

    In the end it's just our theme that overrides the hidden class, we'll fix it with css and respect when hidden is being added.

    See https://git.drupalcode.org/project/facets/-/blob/3.0.x/facets.module?ref...

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mlncn Minneapolis, MN, USA

    OK, fascinating that the hidden class is added rather than the block suppressed. Would like to know why. That approach makes it a lot harder to avoid outputting surrounding markup when there are no facets at all.

    Also, Facets is responsible for adding CSS for classes it relies on; while a common class, hidden cannot be expected on every theme.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium ludo.r Brussels

    My guess (and I bet), that there's a good reason for that.

    Imagine a seach page (99% a views page), where you come with a specific parameter in the URL for Facet A.
    Facet B has no result with param for Facet A.

    If you have an ajax view and uncheck param in Facet A, you might need to show results in Facet B.
    That's a good reason to use the hidden class rather than not showing the block at all.

    Btw, IMHO, I think the hidden class can be used by anyone (theme, contrib module), it's feature of Drupal.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mlncn Minneapolis, MN, USA

    Yeah. And i figured out some whacky CSS to hide the facets section if no facets are visible!

    .facets-views-plugin:has(.block-facet--links) {
      display: none;
    }
    .facets-views-plugin:not(:has(.hidden)) {
      display: flex;
    }
    

    That was our use case, probably display: block will be more common than flex. And the first :has() is not "needed" but it avoids hiding the facets permanently for the dwindling number of browsers (under 8% share) that do not support has.

    Putting this here for anyone else who wants to use it, not for inclusion in Facets.

Production build 0.71.5 2024