The <RefinementList> component displays a list of facet values where users can select multiple values to refine their search.
Import
import { RefinementList } from 'react-instantsearch';
Props
The attribute to create the refinement list from.<RefinementList attribute="brand" />
How to apply multiple selections.<RefinementList attribute="brand" operator="and" />
Maximum number of items to display.<RefinementList attribute="brand" limit={20} />
Whether to display a “Show more” button.<RefinementList attribute="brand" showMore={true} />
Maximum number of items to display when “Show more” is clicked.<RefinementList
attribute="brand"
showMore={true}
showMoreLimit={50}
/>
Whether to display a search box to filter the list.<RefinementList attribute="brand" searchable={true} />
Placeholder text for the search box.<RefinementList
attribute="brand"
searchable={true}
searchablePlaceholder="Search brands..."
/>
Whether to select the first item when submitting the search box.<RefinementList
attribute="brand"
searchable={true}
searchableSelectOnSubmit={false}
/>
sortBy
string[] | function
default:"['isRefined', 'count:desc', 'name:asc']"
How to sort the items.<RefinementList
attribute="brand"
sortBy={['count:desc', 'name:asc']}
/>
Whether to escape the facet values.
Transform the refinement items before displaying them.<RefinementList
attribute="brand"
transformItems={(items) =>
items.map((item) => ({
...item,
label: item.label.toUpperCase(),
}))
}
/>
Customize the text strings.<RefinementList
attribute="brand"
translations={{
showMoreButtonText: ({ isShowingMore }) =>
isShowingMore ? 'Show less' : 'Show more',
noResultsText: 'No results.',
submitButtonTitle: 'Submit',
resetButtonTitle: 'Clear',
}}
/>
CSS classes to customize the component styling.
Example
import { InstantSearch, RefinementList, 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">
<RefinementList attribute="brand" />
<RefinementList attribute="category" />
</aside>
<main>
<SearchBox />
<Hits />
</main>
</div>
</InstantSearch>
);
}
With Search
function App() {
return (
<InstantSearch searchClient={searchClient} indexName="products">
<RefinementList
attribute="brand"
searchable={true}
searchablePlaceholder="Search brands..."
showMore={true}
limit={10}
showMoreLimit={50}
/>
</InstantSearch>
);
}