Signature
Import
- Component
- Plugin
To ensure optimal bundle sizes,
see Optimize build size.
Vue
About this widget
Theais-hierarchical-menu
widget displays a hierarchical navigation menu, based on facet attributes.
To create a hierarchical menu:
- Decide on an appropriate facet hierarchy
- Determine your
attributes
for faceting from the dashboard or with an API client - Display the UI with the hierarchical menu widget.
Requirements
The objects to use in the hierarchical menu must follow this structure:JSON
JSON
>
(with spaces), but you can use a different one by using the separator option.
By default, the count of the refined root level is updated to match the count of the actively refined parent level.
Keep the root level count intact by setting
persistHierarchicalRootCount
in ais-instant-search
.Examples
Vue
Props
The name of the attributes to generate the menu with.To avoid unexpected behavior, you can’t use the same
attribute
prop in a different type of widget.Vue
The number of 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
The level separator used in the records.
Vue
The prefix path to use if the first level is not the root level.Make sure to also include the root path in your UI state,
for example, by setting
initial-ui-state
.Vue
Whether to show the siblings of the selected parent level of the current refined value.This option doesn’t impact the root level. All root items are always visible.
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 this facet’s facetOrdering
is set in renderingContent
, and no sortBy
value is passed to the widget,
facetOrdering
is used with default ordering as a fallback.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-HierarchicalMenu
. The root element of the widgetais-HierarchicalMenu--noRefinement
. The root element of the widget with no refinement.ais-HierarchicalMenu-list
. The list of menu items.ais-HierarchicalMenu-list--child
. The child list of menu items.ais-HierarchicalMenu-list--lvl0
. The level 0 list of menu items.ais-HierarchicalMenu-list--lvl1
. The level 1 list of menu items (and so on).ais-HierarchicalMenu-item
. The menu list item.ais-HierarchicalMenu-item--selected
. The selected menu list item.ais-HierarchicalMenu-item--parent
. The menu list item containing children.ais-HierarchicalMenu-link
. The clickable menu element.ais-HierarchicalMenu-link--selected
. The clickable element of a selected menu list item.ais-HierarchicalMenu-label
. The label of each item.ais-HierarchicalMenu-count
. The count of each item.ais-HierarchicalMenu-showMore
. The button used to display more categories.ais-HierarchicalMenu-showMore--disabled
. This button is 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 list of available items. -
canToggleShowMore: boolean
. Whether users can click the “Show more” button. -
isShowingMore: boolean
. Whether the list is expanded. -
refine: (value: string) => void
. Sets the path of the hierarchical filter and triggers a new search. -
createURL: (value: string) => string
. The function to generate a URL for the next state. -
toggleShowMore: () => void
. Toggles the number of displayed values betweenlimit
andshow-more-limit
. -
sendEvent: (eventType, facetValue) => 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. -
To learn more, see the
insights
middleware. -
eventType: 'click'
-
facetValue: string
-
The
object
containing:label: string
. The label of the item.value: string
. The value of the item.count: number
. The number results matching this value.isRefined: boolean
. Whether the item is selected.data: object[]|null
. The list of children for the current item.
showMoreLabel
The slot to override the show more label.Scope
isShowingMore: boolean
. Whether the list is expanded.
Vue
HTML output
Default
HTML
Without show more
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.