Signature
Import
About this widget
TherefinementList
widget is one of the most common widgets in a search UI.
With this widget, users can filter the dataset based on facets.
The widget only displays the most relevant facet values for the current search context.
The sort option only affects the facets that are returned by the engine, not which facets are returned.
This widget includes a “search for facet values” feature,
enabling users to search through the values of a specific facet attribute.
This makes it easy to find uncommon facet values.
Requirements
Theattribute
provided to the widget must be in attributes for faceting,
either on the dashboard or using the attributesForFaceting
parameter with the API.
If you are using the searchable
prop,
you also need to make the attribute searchable using the dashboard or using the searchable
modifier of attributesForFaceting
with the API.
Disappearing facet values
With many facet values, the available options can change depending on the user’s query. The refinement widget displays the most common facet values for a given query. A user’s chosen value can vanish if they alter the query. This occurs because only the most common facet values are displayed when there are many options. A previously selected value might not appear if it’s uncommon for the new query. To also show less common values, adjust the maximum number of values with theconfigure
widget.
It doesn’t change how many items are shown: the limits you set with limit
and showMoreLimit
still apply.
JavaScript
Examples
JavaScript
Options
The CSS Selector of the DOM element inside which the widget is inserted.
The name of the attribute in the records.To avoid unexpected behavior, you can’t use the same
attribute
prop in a different type of widget.JavaScript
How to apply refinements.
"or"
: apply anOR
between all selected values."and"
: apply anAND
between all selected values.
JavaScript
How many facet values to retrieve.
When you enable the
showMore
feature,
this is the number of facet values to display before clicking the “Show more” button.JavaScript
Whether to display a button that expands the number of items.
JavaScript
The maximum number of displayed items (only used when
showMore
is set to true
).JavaScript
Whether to add a search input to let users search for more facet values.To make this feature work,
you need to make the attribute searchable using the dashboard or using the
searchable
modifier of attributesForFaceting
with the API.In some situations, refined facet values might not be present in the data
returned by Algolia.
JavaScript
The value of the search input’s placeholder.
JavaScript
When
false
, disables the search input if there are fewer items to display than the limit
option.
Otherwise, the search input is always usable.JavaScript
When
true
, escapes the facet values that are returned from Algolia.
In this case, the surrounding tags are always mark
.JavaScript
How to sort refinements. Must be one or more of the following strings:
"count"
(same as"count:desc"
)"count:asc"
"count:desc"
"name"
(same as"name:asc"
)"name:asc"
"name:desc"
"isRefined"
(same as"isRefined:asc"
)"isRefined:asc"
"isRefined:desc"
Array.sort
.If facetOrdering
is set for this facet in renderingContent
,
and no value for sortBy
is passed to this widget, facetOrdering
is used, and the default order as a fallback.In some situations, refined facet values might not be present in the data
returned by Algolia.
The CSS classes you can override:
root
. The root element of the widget.noRefinementRoot
. The root element if there are no refinements.noResults
. The root element if there are no results.list
. The list of results.item
. The list items. They contain the link and separator.selectedItem
. Each selected item in the list.label
. Each label element (when using the default template).checkbox
. Each checkbox element (when using the default template).labelText
. Each label text element.showMore
. The “Show more” element.disabledShowMore
. The disabled “Show more” element.count
. Each count element (when using the default template).searchableRoot
. The root element of the search box.searchableForm
. The form element of the search box.searchableInput
. The input element of the search box.searchableSubmit
. The reset button element of the search box.searchableSubmitIcon
. The reset button icon of the search box.searchableReset
. The loading indicator element of the search box.searchableResetIcon
. The loading indicator icon of the search box.searchableLoadingIndicator
. The submit button element of the search box.searchableLoadingIcon
. The submit button icon of the search box.
JavaScript
A function that receives the list of items before they are displayed.
It should return a new array with the same structure.
Use this to transform, filter, or reorder the items.The function also has access to the full
results
data,
including all standard response parameters
and parameters from the helper,
such as disjunctiveFacetsRefinements
.JavaScript
Templates
You can customize parts of a widget’s UI using the Templates API. Each template includes anhtml
function,
which you can use as a tagged template.
This function safely renders templates as HTML strings and works directly in the browser—no build step required.
For details, see Templating your UI.
The
html
function is available in InstantSearch.js version 4.46.0 or later.The template used for an item. It exposes:
count
. The number of occurrences of the facet in the result set.isRefined
. Returnstrue
if the value is selected.label
. The label to display.value
. The value used for refining.highlighted
. The highlighted label (when using search for facet values). This value is displayed in the default template.url
. The URL with the selected refinement.cssClasses
. An object containing all the computed classes for the item.
The template for the “Show more” button text. It exposes:
isShowingMore: boolean
. Whether the list is expanded.
The template used for when there are no results.
The template used for displaying the submit button.
The template used for displaying the reset button.
The template used for displaying the loading indicator.
Customize the UI with connectRefinementList
If you want to create your own UI of the refinementList
widget, you can use connectors.
To use connectRefinementList
, you can import it with the declaration relevant to how you installed InstantSearch.js.
JavaScript
Create a render function
This rendering function is called before the first search (init
lifecycle step)
and each time results come back from Algolia (render
lifecycle step).
JavaScript
Rendering options
The list of refinement values returned from the Algolia API.Each object has the following properties:
value: string
: the value of the item.label: string
: the label of the item.count: number
: the number of results that match the item.isRefined: boolean
: indicates if the refinement is applied.
JavaScript
Indicates if search state can be refined.
JavaScript
A function to toggle a refinement.
JavaScript
The function to send
click
events. The click
event is automatically sent when refine
is called.
To learn more, see the insights
middleware.eventType: 'click'
facetValue: string
JavaScript
Generates a URL for the corresponding search state.
JavaScript
Whether the
items
prop contains facet values from the global search or from the search inside the items.JavaScript
A function to trigger a search inside item values.To make this feature work, you need to make the attribute searchable using the dashboard or using the
searchable
modifier of attributesForFaceting
with the API.JavaScript
Whether the results are complete.
JavaScript
Returns
true
if the menu is displaying all the menu items.JavaScript
Returns
true
if the “Show more” button can be activated (if enough items to display and not already displaying more than limit
items).JavaScript
Toggles the number of displayed values between
limit
and showMoreLimit
.JavaScript
All original widget options forwarded to the render function.
JavaScript
Create and instantiate the custom widget
First, create your custom widgets using a rendering function. Then, instantiate them with parameters. There are two kinds of parameters you can pass:- Instance parameters. Predefined options that configure Algolia’s behavior.
- Custom parameters. Parameters you define to make the widget reusable and adaptable.
renderFunction
, both instance and custom parameters are accessible through connector.widgetParams
.
JavaScript
Instance options
The name of the attribute in the records.To avoid unexpected behavior, you can’t use the same
attribute
prop in a different type of widget.JavaScript
How to apply refinements.
"or"
: apply anOR
between all selected values."and"
: apply anAND
between all selected values.
JavaScript
How many facet values to retrieve.
When isShowingMore is
false
,
this is the number of facet values displayed before clicking the “Show more” button.JavaScript
The maximum number of items to display if the widget is showing more items.
Needs to be bigger than the
limit
parameter.JavaScript
When activate, escapes the facet values that are returned from Algolia.
In this case, the surrounding tags are always
mark
.JavaScript
How to sort refinements. Must be one or more of the following strings:
"count:asc"
"count:desc"
"name:asc"
"name:desc"
"isRefined"
Array.sort
.If facetOrdering
is set for this facet in renderingContent
,
and no value for sortBy
is passed to this widget, facetOrdering
is used, and the default order as a fallback.In some situations, refined facet values might not be present in the data
returned by Algolia.
A function that receives the list of items before they are displayed.
It should return a new array with the same structure.
Use this to transform, filter, or reorder the items.The function also has access to the full
results
data,
including all standard response parameters
and parameters from the helper,
such as disjunctiveFacetsRefinements
.JavaScript