How to not clear virtual filters on 'Clear All Filters' button pressed

Hey :wave:

I have a search form where I use VirtualMenu from react-instantsearch to pre-filter results for the user. I also have a “Clear All Filters” button that uses the connectCurrentRefinements connector. How can I tell the connector to clear all but the virtual filters?

Thanks :smile:

Hi @jm1
You can just filter out the attribute referenced by the VirtualMenu in the transformItems exposed by connectCurrentRefinements.

See how we do it for the facet “brands” on our example:


<CustomClearRefinements
  transformItems={items =>
    items.filter(({ attribute }) => attribute !== 'brand')
  }
/>

Let me know if this helped.

1 Like