Signature
Import
- Component
- Plugin
To ensure optimal bundle sizes,
see Optimize build size.
Vue
About this widget
Theais-refinement-list
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 show-more-limit
still apply.
Examples
Vue
Props
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.Vue
How to apply refinements.
'or'
: Returns results matching any of the selected values.'and'
: Returns results matching all selected values.
Vue
How many facet values to retrieve.
When you enable the
show-more
feature,
this is the number of facet values to display before clicking the “Show more” button.Vue
Whether to display a button that expands the number of items.
Vue
The maximum number of displayed items (only used when
show-more
is set to true
).Vue
Adds 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.
Vue
The value of the search input placeholder.
Vue
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.To prevent creating infinite loops,
avoid passing arrays, objects, or functions directly in the template.
These values aren’t referentially equal on each render,
which causes the widget to re-register every time.
Instead, define them in your component’s
data
option and reference them in the template.Vue
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
.Vue
The CSS classes you can override:
.ais-RefinementList
. The root element of the widget..ais-RefinementList--noRefinement
. The root element of the widget with no refinement..ais-RefinementList-list
. The list of all items..ais-RefinementList-item
. The list item..ais-RefinementList-item--selected
. The selected list item..ais-RefinementList-label
. The label of each item..ais-RefinementList-labelText
. The text of the label of each item..ais-RefinementList-checkbox
. The checkbox element..ais-RefinementList-count
. The count of values for each item..ais-RefinementList-searchBox
. The search box when the widget is searchable..ais-RefinementList-noResults
. The element rendered when the search doesn’t have results..ais-RefinementList-showMore
. The button used to display more categories (enabled)..ais-RefinementList-showMore--disabled
. The button used to display more categories (turned off).
Vue
Customize the UI
default
The slot to override the complete DOM output of the widget.When you implement this slot, none of the other slots will change the output, as the default slot surrounds them.Scope
-
items: object[]
. The values applicable to this widget. -
isShowingMore: boolean
. Isshow-more
enabled? -
isFromSearch: boolean
.true
if there are search results. -
canRefine: boolean
. Can the refinement be applied? -
canToggleShowMore: boolean
. Isshow-more
possible? -
toggleShowMore: () => void
. Toggles the number of displayed values betweenlimit
andshow-more-limit
. -
searchForItems: (value: string) => void
. A function to search into the facet values. -
refine: (value: string) => void
. A function to select a refinement. -
createURL: (value: string) => string
. A function to return a link for this refinement. -
sendEvent: (eventType: 'click', facetValue: string) => void
. The function to sendclick
events.- The
view
event is automatically sent when the facets are rendered. - The
click
event is automatically sent whenrefine
is called. - You can learn more about the
insights
middleware.
- The
object
containing:value: string
. The value of the item.label: string
. The human-readable value of the item.count: number
. The number of matched results after a refinement is applied.isRefined: boolean
. Indicates if the refinement is applied.
Vue
item
The slot to override the DOM output of an item.Scope
item: object
. An item object.refine: (Item.value) => void
. A function to select a refinement.createURL: (Item) => string
. A function to return a link for this refinement.
object
containing:value: string
. The value of the item.label: string
. The human-readable value of the item.count: number
. The number of results matched after a refinement is applied.isRefined: boolean
. Indicates if the refinement is applied.
Vue
showMoreLabel
The slot to override the DOM output of the “Show more” button.Scope
isShowingMore: boolean
. Is the list of items expanded?
Vue
noResults
The slot to override the DOM output of the no results placeholder.Scope
query: string
. The current value of the query.
Vue
HTML output
HTML