Skip to main content
Signature

Explore example code

Browse the Hierarchical Menu example code on GitHub.

About this widget

A Hierarchical Menu is a component that displays a hierarchical navigation menu, based on facet attributes.

Examples

Instantiate a HierarchicalConnector and launch an initial search on its Searcher.
Swift

Parameters

searcher
HitsSearcher
required
The Searcher that handles your searches.
filterState
FilterState
required
The FilterState that holds your filters.
hierarchicalAttributes
[Attribute]
required
The names of the hierarchical attributes to target, in ascending order.
separator
String
required
The delimiter used to separate hierarchical facets. Usually something like ” > ”, including spaces as shown in this example.
controller
HierarchicalController
default: nil
The Controller interfacing with a concrete hierarchical view.
presenter
HierarchicalPresenter
default: nil
The Presenter defining how hierarchical facets appear in the controller.

Presenter

Hierarchical Presenter
(([HierarchicalFacet]) -> [HierarchicalFacet])?
default:"nil"
The presenter defining how to display the HierarchicalFacet list.Takes a list of HierarchicalFacet as input and returns a new HierarchicalFacet list.A HierarchicalFacet is a tuple of a Facet, its level, and whether it’s selected or not.
Swift

Low-level API

If you want to fully control the Hierarchical Menu components and connect them manually, you can use the following components:
  • Searcher. The Searcher that handles your searches.
  • FilterState. The current state of the filters.
  • HierarchicalInteractor. The logic applied to the hierarchical facets.
  • HierarchicalController. The controller that interfaces with a concrete hierarchical facet list view.
  • HierarchicalPresenter. Optional. The presenter that controls the sorting and other settings of the refinement facet list view.
Swift

Customizing your view

The default controllers, for example, HierarchicalTableViewController, work well when you want to use native UIKit with their default behavior. If you want to use another component such as a UICollectionView, a third-party input view, or you want to introduce some custom behavior to the already provided UIKit component, you can create your own controller conforming to the HierarchicalController protocol.

Protocol

var onClick: ((String) -> Void)?: Closure to call when a new hierarchical facet is clicked. func setItem(_ item: [HierarchicalFacet]) Function called when a new array of hierarchical facets is updated. This is the UI State of the refinement list. Make sure to reload your view here when you get the new items.

Example

Swift

SwiftUI

InstantSearch provides the HierarchicalList SwiftUI view which you can embed in your views. It uses HierarchicalObservableController as a data model, which is an implementation of the HierarchicalController protocol adapted for usage with SwiftUI. HierarchicalObservableController must be connected to the HierarchicalConnector or HierarchicalInteractor like any other HierarchicalController implementation. You can define the appearance of the view representing a single hierarchical facet and its selection state or use the HierarchicalFacetRow view provided by InstantSearch.
Swift
If you prefer to create a custom SwiftUI view that presents the list of hierarchical facets, you can directly use the HierarchicalObservableController as a data model. It provides the hierarchicalFacets property along with the toggle function to streamline the design process of your custom SwiftUI view.
Last modified on July 10, 2026