Autocomplete Result List

The autocomplete-result-list component displays the autocomplete functionality in the search bar. This component serves mainly to ease the creation of custom autocomplete components for search engines.

autocomplete-bar-gifautocomplete-bar-gif

Configuration

  1. Import the vtex.store-components app to your theme's dependencies in the manifest.json file as in the following example:
  "dependencies": {
    "vtex.store-components": "3.x"
  }
  1. Add the autocomplete-result-list block into the search-bar component. For example:
  "search-bar": {
    "blocks": [
+     "autocomplete-result-list"
    ]
  }
  1. Then, declare the autocomplete-result-list block using the props stated in the Props table.

Props

️ Info

The autocomplete-result-list block is commonly used with Downshift. Hence, some of its props are directly related to it.

Prop nameTypeDescriptionDefault value
attemptPageTypeSearchBooleanUses the input term to try to navigate to the proper page type (e.g. a department, a brand, a category) if true.-
classesCustomCSSClassesOverrides default CSS handles. To better understand how this prop works, check this document. Note that this is only helpful if you're using this block as a React component.undefined
closeMenu (Downshift)FunctionCloses the menu.-
customSearchPageUrlStringTemplate for a custom URL. It accepts a substring ${term} as placeholder to interpolate the searched term (e.g., /search?query=${term}).-
dataObjectGraphql data response.{}
highlightedIndex (Downshift)NumberThe index that should be highlighted.-
getItemProps (Downshift)FunctionReturns the props for every menu item element being rendered.-
getMenuProps (Downshift)FunctionReturns the props for the ul or root element of your menu.-
inputValueStringSearch query.-
onClearInputFunctionClears the input.-
isOpenBooleanIdentifies if the autocomplete should be opened.-

Customization

To apply CSS customizations in this and other blocks, follow the Using CSS handles for store customization guide.

CSS Handles
resultsItem
resultsItemImage
resultsItemName
resultsList
searchTerm
spinnerContainer
spinnerInnerContainer

Did this page help you?