Signature
Import
About this widget
ThemenuSelect
widget allows a user to select a single value to refine inside a select
element.
Requirements
Theattribute
provided to the widget must be in attributes for faceting,
either on the dashboard or using the attributesForFaceting
parameter with the API.
Examples
JavaScript
Options
The CSS Selector or
HTMLElement
to insert the widget into.The name of the attribute in the record.
JavaScript
The maximum number of values to display.
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.TThe CSS classes you can override:
root
. The root element of the widget.noRefinementRoot
. The root element if there are no refinements.select
. Theselect
element.option
. Theoption
elements of theselect
.
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 to customize each
option
element. It exposes:label: string
. The label to display in the option.value: string
. The value for the option.count: number
. The number of hits that match this value.isRefined: boolean
. Indicates if it’s the current refined value.
The template to customize the first option of the select.
HTML output
HTML
Customize the UI with connectMenu
If you want to create your own UI of the menuSelect
widget, you can use connectors.
This connector is also used to build the
menu
widget.connectMenu
, 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
If SEO is important for your search page, ensure that your custom HTML is optimized for search engines:
- Use
<a>
tags withhref
attributes to allow search engine bots to follow links. - Use semantic HTML and include structured data when relevant.
Rendering options
The elements that can be refined for the current search results. With each item:
value: string
. The value of the menu item.label: string
. The label of the menu item.count: number
. The number of matched results after a refinement is applied.isRefined: boolean
. Indicates if the refinement is applied.
JavaScript
Returns
true
if a refinement can be applied.JavaScript
Sets the refinement and triggers a search.
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
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 record.
JavaScript
The maximum number of values to display.
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
.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