typeToSearch Methods

Prev Next

The typeToSearch methods are used to control the type-to-search behavior.

typeToSearch.search()

Used to trigger a type-to-search query. This query will still respect the debounce and response timeout settings as defined in the getTypeToSearch options.

Note: this function is called automatically on key press if bound to an input.

Parameters passed to the search method:

NAME/TYPE

DESCRIPTION

query

string

The search term that will be used to find relevant products.

options

TypeToSearchSearchOptions

The options that will control the behavior of the type-to-search query.

typeToSearch.search() Options

The type-to-search search method accepts the following options:

NAME/TYPE

DESCRIPTION

context

object

An object containing the contextual variables used for filters.

Note: this context will be combined with the context used in the context property above

key
string

Note: for XGen rendered deployments only.

The most recent key that was pressed on the keyboard. Used for tts activation settings.

typeToSearch.bindInput()

Used to bind an HTML Input element to the type-to-search object. Any character the users types within that element will fire the search method above on the set debounce.

Parameters passed to the bindInput method:

NAME/TYPE

DESCRIPTION

input

HTMLInputElement

The HTML Input element that will be listened to for the user typing.

Example

Binding a search input:

// Start a type to search session
const tts = getTypeToSearch(console.log, { deploymentId: '3d8e3aa4-b1e9-4b1b-9ff6-ca4bc64806d0' });

// Grab the input from the DOM
const inputElement = document.querySelector('input.searchInput');

// Bind the search input
tts.bindInput(inputElement);