Skip to content

searchPhraseSubmitted

searchPhraseSubmitted is a DOM event that occurs whenever the search request in the h-storefront-search webcomponent is performed.

Event body

The searchPhraseSubmitted body has a TSearchPhaseEventBody type which represents the details of the submitted search phrase. It is optional so it might not exist.

Example

In this example we listen to searchPhraseSubmitted event and perform an action whenever it's emitted.

useStorefront(async (storefront) => {
    document.addEventListener('searchPhraseSubmitted', (event) => {
        const detail = event.detail;

        if (!detail) return;

        const { searchPhrase, moduleInstanceId } = detail;

        console.log('Search of id ', moduleInstanceId, ' has been submitted with value:', searchPhrase);
    });
});