The <Menu> component displays a list of facet values where users can select a single value to refine their search.
Import
import { Menu } from 'react-instantsearch';
Props
The attribute to create the menu from.<Menu attribute="brand" />
Maximum number of items to display.<Menu attribute="brand" limit={20} />
Whether to display a “Show more” button.<Menu attribute="brand" showMore={true} />
Maximum number of items to display when “Show more” is clicked.<Menu attribute="brand" showMore={true} showMoreLimit={50} />
sortBy
string[] | function
default:"['isRefined', 'name:asc']"
How to sort the items.<Menu attribute="brand" sortBy={['count:desc', 'name:asc']} />
Transform the menu items before displaying them.<Menu
attribute="brand"
transformItems={(items) =>
items.map((item) => ({
...item,
label: item.label.toUpperCase(),
}))
}
/>
Customize the text strings.<Menu
attribute="brand"
translations={{
showMoreButtonText: ({ isShowingMore }) =>
isShowingMore ? 'Show less' : 'Show more',
}}
/>
CSS classes to customize the component styling.
Example
import { InstantSearch, Menu, SearchBox, Hits } from 'react-instantsearch';
import { liteClient as algoliasearch } from 'algoliasearch/lite';
const searchClient = algoliasearch(
'YourApplicationID',
'YourSearchOnlyAPIKey'
);
function App() {
return (
<InstantSearch searchClient={searchClient} indexName="products">
<div className="container">
<aside className="filters">
<Menu attribute="brand" />
<Menu attribute="category" />
</aside>
<main>
<SearchBox />
<Hits />
</main>
</div>
</InstantSearch>
);
}
With Show More
function App() {
return (
<InstantSearch searchClient={searchClient} indexName="products">
<Menu
attribute="brand"
showMore={true}
limit={10}
showMoreLimit={50}
sortBy={['count:desc']}
/>
</InstantSearch>
);
}