For the complete documentation index, see llms.txt. This page is also available as Markdown.

Suggest

Render FactFinder suggestions and Popular Searches with section-based templates in `ff-suggest`.

Documentation

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".

<ff-suggest no-auto-highlight>
    <template data-role="suggestions">
        <section>
            <div data-container="suggestType">
                <span>Suggestions for suggestType</span>
                <div>
                    <!--ff-suggest-items are always added at the original position of the template-->
                    <ff-suggest-item type="suggestType">
                        <div>{{{ff-hitHighlight name}}}</div>
                        <img width="100" height="100" data-image />
                    </ff-suggest-item>
                </div>
            </div>
        </section>
    </template>
</ff-suggest>

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-highlight attribute on ff-suggest.

  • Use triple curly braces in the data binding.

  • Add the ff-hitHighlight formatter 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 Engine for details.

The ff-hitHighlight formatter wraps the text in the relevant HTML without modifying the original data.

The no-auto-highlight attribute is necessary to prevent the component from overwriting the suggest-item's original data with the HTML wrapper instead of applying it only to the display layer.

This is an internal artifact of an old integration method. In a future version, no-auto-highlight will become redundant.

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.

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

API

ff-suggest


Properties

Name
Description

no-auto-highlight (Boolean)

Always set this attribute! Ensures underlying data does not get corrupted. Use together with {{{ff-hitHighlight name}}} formatter.

suggest-items (Array)

The data from FactFinder.

hide-onblur (String) Options: "true", "false" (default: "true")

When "true", clicks outside the Suggest and the related ff-searchbox close the Suggest popup.

hide-delay (Number) (default: 300)

Defines the time in milliseconds the Suggest popup remains open after it received a hide command. Some delay is necessary because certain input devices trigger their click event with a delay (e.g. touchpads). Increase this value if it seems the Suggest closes too fast when you click on it.

request-mapping-search (String, comma-separated list) (default: "searchTerm")

A list of suggest types that shall invoke a search request.

request-mapping-navigation (String, comma-separated list) (default: "category,brand")

A list of suggest types that shall invoke a navigation request.

request-mapping-detail (String, comma-separated list) (default: "productName")

A list of suggest types that shall invoke the suggest-detail-listener from the factfinder.notifications API.

for-searchbox (String, comma-separated list) (default: empty)

A list of ff-searchbox id's to which ff-suggest shall react to. If empty, ff-suggest will react to all Suggest requests.

ff-suggest-item


Properties

Name
Description

type (String) Options: "product", "brand", "search", "category", "all" (default: "all")

The suggest type as it corresponds to your suggest type configuration in the FactFinder UI.

suggestion

The item's data from FactFinder.

Last updated

Was this helpful?