Signature
Import
- Component
- Plugin
To ensure optimal bundle sizes,
see Optimize build size.
Vue
About this widget
Theais-menu
widget displays a menu that lets users choose a single value for a specific attribute.
The
ais-menu
widget uses a hierarchical refinement internally, so it can’t refine values that include the default separator (>
).
To support these values, use the ais-hierarchical-menu
widget instead.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
Vue
Props
The name of the attribute in the record.To avoid unexpected behavior, you can’t use the same
attribute
prop in a different type of widget.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
Amount of items to show if showing more.
Requires
show-more
to be true
.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.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-Menu
. The root element of the widget..ais-Menu--noRefinement
. The root element of the widget with no refinement..ais-Menu-list
. The list of all menu items..ais-Menu-item
. The menu list item..ais-Menu-item--selected
. The selected menu list item..ais-Menu-link
. The clickable menu element..ais-Menu-label
. The label of each item..ais-Menu-count
. The count of values for each item..ais-Menu-showMore
. The button used to display more categories..ais-Menu-showMore--disabled
. The disabled button used to display more categories.
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 menu. -
canRefine: boolean
. Can the refinement be applied? -
canToggleShowMore: boolean
. Is show-more possible? -
isShowingMore: boolean
. Is show-more enabled? -
refine: (value: string) => void
. The function to select a refinement. -
createURL: (value: string) => string
. The 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 menu item.label: string
. The human-readable value of the menu 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 for the label of the “Show more” button.Scope
isShowingMore: boolean
. Is show-more enabled?
Vue
HTML output
HTML
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.