The currentRefinements widget displays a list of all active filters and allows users to remove them individually. It provides a clear overview of the current search context.
Usage
const currentRefinements = instantsearch . widgets . currentRefinements ({
container: '#current-refinements' ,
});
search . addWidget ( currentRefinements );
Examples
Basic Current Refinements
instantsearch . widgets . currentRefinements ({
container: '#current-refinements' ,
});
With Included Attributes
instantsearch . widgets . currentRefinements ({
container: '#current-refinements' ,
includedAttributes: [ 'brand' , 'category' ],
});
With Excluded Attributes
instantsearch . widgets . currentRefinements ({
container: '#current-refinements' ,
excludedAttributes: [ 'query' ],
});
instantsearch . widgets . currentRefinements ({
container: '#current-refinements' ,
transformItems : ( items ) =>
items . map (( item ) => ({
... item ,
label: item . label . toUpperCase (),
})),
});
Options
container
string | HTMLElement
required
CSS Selector or HTMLElement to insert the widget.
List of attributes to include. When provided, only refinements from these attributes are displayed.
List of attributes to exclude from the display.
Function to transform the items before rendering. ( items : object []) => object []
Each item contains:
attribute: The attribute name
label: Display label for the attribute
refinements: Array of active refinements for this attribute
refine: Function to remove refinements
CSS classes to add to the widget elements. CSS class for the root element.
CSS class when there are no refinements.
CSS class for the list element.
CSS class for the category.
CSS class for the category label.
CSS class for the delete button.
HTML Output
< div class = "ais-CurrentRefinements" >
< ul class = "ais-CurrentRefinements-list" >
< li class = "ais-CurrentRefinements-item" >
< span class = "ais-CurrentRefinements-label" > Brand: </ span >
< span class = "ais-CurrentRefinements-category" >
< span class = "ais-CurrentRefinements-categoryLabel" > Apple </ span >
< button class = "ais-CurrentRefinements-delete" type = "button" > ✕ </ button >
</ span >
< span class = "ais-CurrentRefinements-category" >
< span class = "ais-CurrentRefinements-categoryLabel" > Samsung </ span >
< button class = "ais-CurrentRefinements-delete" type = "button" > ✕ </ button >
</ span >
</ li >
< li class = "ais-CurrentRefinements-item" >
< span class = "ais-CurrentRefinements-label" > Price: </ span >
< span class = "ais-CurrentRefinements-category" >
< span class = "ais-CurrentRefinements-categoryLabel" > 10 - 500 </ span >
< button class = "ais-CurrentRefinements-delete" type = "button" > ✕ </ button >
</ span >
</ li >
</ ul >
</ div >
Refinement Types
The widget displays different types of refinements:
Facet Refinements
Shows selected facet values from widgets like refinementList, menu, or hierarchicalMenu.
Numeric Refinements
Displays numeric ranges from rangeInput, rangeSlider, or numericMenu widgets.
Query Refinements
Shows the search query from the searchBox widget (unless excluded).
Customization
You can customize how refinements are displayed:
instantsearch . widgets . currentRefinements ({
container: '#current-refinements' ,
transformItems : ( items ) =>
items . map (( item ) => {
// Customize the label
const label = item . attribute === 'brand' ? 'Brands' : item . label ;
// Customize refinement display
const refinements = item . refinements . map (( refinement ) => ({
... refinement ,
label: refinement . label . toUpperCase (),
}));
return {
... item ,
label ,
refinements ,
};
}),
});
Combine with clearRefinements
Often used together with the clearRefinements widget:
// Show current refinements
instantsearch . widgets . currentRefinements ({
container: '#current-refinements' ,
});
// Add clear all button
instantsearch . widgets . clearRefinements ({
container: '#clear-refinements' ,
});