The menu widget displays a list of facet values where users can select only one value at a time. It’s ideal for mutually exclusive filters like product type or department.
Usage
const menu = instantsearch . widgets . menu ({
container: '#category-menu' ,
attribute: 'category' ,
});
search . addWidget ( menu );
Examples
instantsearch . widgets . menu ({
container: '#category' ,
attribute: 'category' ,
limit: 10 ,
});
With Show More
instantsearch . widgets . menu ({
container: '#brands' ,
attribute: 'brand' ,
limit: 5 ,
showMore: true ,
showMoreLimit: 20 ,
});
With Custom Sorting
instantsearch . widgets . menu ({
container: '#types' ,
attribute: 'type' ,
sortBy: [ 'count:desc' , 'name:asc' ],
});
Options
container
string | HTMLElement
required
CSS Selector or HTMLElement to insert the widget.
The name of the attribute in your records. Must be declared as an attribute for faceting.
Maximum number of facet values to display.
Whether to display a “Show more” button.
Maximum number of facet values when “Show more” is clicked.
sortBy
string[] | function
default: "['name:asc']"
How to sort refinements. Available values:
'count:asc' / 'count:desc'
'name:asc' / 'name:desc'
'isRefined'
Function to transform the items before rendering. ( items : object []) => object []
Templates to customize the widget rendering. Template for each item. Receives count, label, value, isRefined, url.
Template for the “Show more” button. Receives isShowingMore.
CSS classes to add to the widget elements. CSS class for the root element.
CSS class when no refinements are available.
CSS class for the list element.
CSS class for the selected item.
HTML Output
< div class = "ais-Menu" >
< ul class = "ais-Menu-list" >
< li class = "ais-Menu-item ais-Menu-item--selected" >
< a class = "ais-Menu-link" href = "#" >
< span class = "ais-Menu-label" > Electronics </ span >
< span class = "ais-Menu-count" > 4,123 </ span >
</ a >
</ li >
< li class = "ais-Menu-item" >
< a class = "ais-Menu-link" href = "#" >
< span class = "ais-Menu-label" > Clothing </ span >
< span class = "ais-Menu-count" > 2,984 </ span >
</ a >
</ li >
</ ul >
< button class = "ais-Menu-showMore" > Show more </ button >
</ div >
Requirements
The attribute must be declared as an attribute for faceting in your Algolia index settings.