Suggest
Build and customize interactive FactFinder suggestions.
Documentation
API reference
ff-suggest
ff-suggest-item
The basics
Two features in one element
The ff-suggest element can render both regular Suggestions and Popular Searches.
This article focuses on the setup for regular suggestions.
See the Popular Searches article for details.
Templating concept
The suggestions template is defined through a template element with the data-role="suggestions" attribute.
It only accepts section elements at the root level. This is due to legacy constraints. A future version will remove this requirement.
Adding a Suggest container
You need to annotate an element with the data-container="suggestType" attribute for each suggest type configured in the FactFinder UI.
The ff-suggest element hides the annotated container if no suggestions are found for this type.
In addition, you need to add an ff-suggest-item element inside the container. All received suggestions of this "suggestType" are inserted at this position and will be an exact copy of this element.
ff-suggest-item supports image binding.
Repeat this process for all configured "suggestTypes".
Hit highlighting
You can highlight the parts in the Suggest's response that match the query in the search box.
Matches are wrapped in a <span class="ffw-query"> element so you can apply appropriate CSS.
Using hit highlighting requires three parts:
Set the
no-auto-highlightattribute onff-suggest.Use triple curly braces in the data binding.
Add the
ff-hitHighlightformatter into the data binding.
The triple curly braces in <span>{{{ff-hitHighlight name}}}</span> tell the template engine to interpret the HTML instead of render it as plain text.
See Template for details.
The ff-hitHighlight formatter wraps the text in the relevant HTML without modifying the original data.
Rendered HTML
Container templates provided inside the ff-suggest tag will be rendered inside several additional div elements.
For example, consider the following HTML setup.
Suppose there are two suggestions of suggestType. This will result in the following HTML output.
When the template clashes with 3rd party frameworks
3rd party rendering frameworks might also use the template element to define their templates.
It can happen that those frameworks 'steal' the template from Web Components and leave a broken ff-suggest.
There are two fallback methods to define the templates for suggestions and popularSearches. While the wrapping template tag is replaced, the template's body remains the same.
Your rendering framework might accept one these approaches.
ff-searchbox properties for Suggest
The ff-searchbox element has two attributes which affect ff-suggest.
The use-suggest attribute determines whether ff-searchbox sends Suggest requests on input.
With the suggest-onfocus attribute, you can define if the Suggest opens when the ff-searchbox gains focus. Possible values are "true" and "false" (default is "false").
For more information see the ff-searchbox page.
Add Keyboard Support
Keyboard arrow key support is enabled by default.
When a ff-suggest-item is selected using the arrow keys, the class ffw-highlight-suggest-item is added to its class list. So you simply need to add CSS rules to highlight the selected item.
Overriding the default click action
To override the action that happens on click/tap, you can use the notifications API of the Web Components core.
This is the first station in the Suggest click pipeline.
In the listener you can perform any task you require and then decide whether you want to resume the pipeline or interrupt it.
You can subscribe multiple listeners. To interrupt the pipeline it is enough if one listener returns false.
Note that returning false does not prevent subsequent listeners from being invoked. Each click will always invoke all listeners.
Navigate on click
The expected behavior after clicking on an ff-suggest-item element of type productName is a navigation to the clicked product's detail page.
ff-suggest automatically performs this action if the suggestion data contains a deeplink field.
The deeplink field is populated with the data from your data feed export column configured with the Deeplink field role.
If no deeplink is provided for an item of type productName, the pipeline will skip this step.
See the Suggest click pipeline diagram for a visualization of the exact data flow.
Closing the Suggest popup
The Suggest's popup automatically closes when the element detects a click that happened outside the popup and outside the ff-searchbox that triggered the Suggest.
Note that custom search boxes are not recognized and clicking into them closes the popup because they are considered "outside".
It does so by adding a click listener to the page's document object.
You can prevent automatic closing by setting the hide-onblur attribute to "false".
Issues with touchpads and other input methods
Some input devices such as touchpads emit a delayed click event.
If this delay is too long, it can happen that the Suggest closes before your click on a suggestion is registered and nothing happens.
ff-suggest's default delay should be long enough to capture all devices without feeling sluggish.
If, however, your users are still experiencing problems, you can increase the hide-delay value until you observe consistent behavior.
See the related API reference.
Triggering the Suggest manually
Even though typically not necessary, you can invoke Suggest requests via Web Components' JavaScript API as you can with any other request type.
This request will travel through the request and response pipelines as usual. However, no ff-suggest element will react to it.
ff-suggest is designed to closely interact with ff-searchbox and apply some optimizations.
In order to have ff-suggest react to your manual request invocation, you have to supply an origin that mimics ff-searchbox.
This can be an actual HTML input element or an object with a value field.
The values of value and query must match.
If your ff-suggest has the for-searchbox attribute configured, you additionally have to specify an id on your origin.
Demo
Try the Suggest demo.
API code
ff-suggest
Properties
Events
ff-suggest-item
Properties
Events
Last updated
Was this helpful?