Recombee Docs
Visit recombee.comStart Free
docs20User Documentation
adminuiAdmin UI
reql32ReQL
codeAPI Clients & Integrations
cookhatScenario Recipes
suitcaseMisc
Widget SDKs / Quick Search / Search Quick Widget (JS)

Quick Search Widget (JS)

A Vanilla JS widget that enables users to perform real-time product searches with instant results, enhancing product discoverability and conversion.

Use this library when you want to display a widget without using a transpiler like Babel and without using JSX. This library exports a htm HTML factory to assemble custom elements of the widget.

This widget library is version 0.1.11 and the API can change. Please specify exact version when installing.

Install @recombee/quick-search-widget-js@0.1.11 and recombee-js-api-client packages using your preferred NPM package manager. This example is using pnpm.

pnpm add @recombee/quick-search-widget-js@0.1.11 recombee-js-api-client
Copy

Always remember to apply the default CSS file distributed alongside the widget library, as shown in the examples.

The widget loads recommendation data using Recombee API Client. Here is how to initialize the client with necessary configuration for a specific database:

import { class ApiClient
Client for sending requests to Recombee and getting replies
ApiClient
} from "recombee-js-api-client";
const const DATABASE_ID: "[database-id]"DATABASE_ID = "[database-id]"; const const PUBLIC_TOKEN: "[database-public-token]"PUBLIC_TOKEN = "[database-public-token]"; const const REGION: "[database-region]"REGION = "[database-region]"; export const const apiClient: ApiClientapiClient = new new ApiClient(databaseId: string, publicToken: string, options?: ApiClientOptions): ApiClient
@paramdatabaseId - ID of your database.@parampublicToken - Corresponding public token.@paramoptions - Other custom options.
ApiClient
(const DATABASE_ID: "[database-id]"DATABASE_ID, const PUBLIC_TOKEN: "[database-public-token]"PUBLIC_TOKEN, {
region?: string | undefinedregion: const REGION: "[database-region]"REGION, });
Copy

The Database Public Token can be found in the Admin UI Database Settings Page.

The widget also needs to be provided a createRequest function, which instantiates a client request class to define which data to pull from the database. Use Scenario ID which can be found on Admin GUI Database Scenarios Page.

Quick Search widget requires the createRequest function to return a Batch Request. For a basic case of single search request, always wrap it in a batch.

import { type 
type CreateRequestFunction = (options: {
    searchQuery: string;
    isFullScreen?: boolean;
}) => Request
CreateRequestFunction
} from "@recombee/quick-search-widget-react";
import { class Batch
In many cases, it may be desirable to execute multiple requests at once. For example, when synchronizing the catalog of items in a periodical manner, you would have to execute a sequence of thousands of separate POST requests, which is very ineffective and may take a very long time to complete. Most notably, network latencies can make execution of such sequence very slow and even if executed in multiple parallel threads, there will still be unreasonable overhead caused by the HTTP(s). To avoid the mentioned problems, batch processing may be used, encapsulating a sequence of requests into a single HTTPS request. Batch processing allows you to submit arbitrary sequence of requests and the batch may combine different types of requests arbitrarily as well. Note that the status code of the batch request itself is 200 even if the individual requests result in error – you have to inspect the code values in the resulting array.
Batch
, class SearchItems
Full-text personalized search. The results are based on the provided `searchQuery` and also on the user's past interactions (purchases, ratings, etc.) with the items (items more suitable for the user are preferred in the results). All the string and set item properties are indexed by the search engine. This endpoint should be used in a search box on your website/app. It can be called multiple times as the user is typing the query in order to get the most viable suggestions based on the current state of the query, or once after submitting the whole query. The returned items are sorted by relevance (the first item being the most relevant). Besides the recommended items, also a unique `recommId` is returned in the response. It can be used to: - Let Recombee know that this search was successful (e.g., user clicked one of the recommended items). See [Reported metrics](https://docs.recombee.com/admin_ui.html#reported-metrics). - Get subsequent search results when the user scrolls down or goes to the next page. See [Recommend Next Items](https://docs.recombee.com/api.html#recommend-next-items). It is also possible to use POST HTTP method (for example in the case of a very long ReQL filter) - query parameters then become body parameters.
SearchItems
, class SearchItemSegments
Full-text personalized search that returns Segments from a Segmentation. The results are based on the provided `searchQuery` and also on the user's past interactions (purchases, ratings, etc.). Based on the used Segmentation, this endpoint can be used for example for: - Searching within categories or brands - Searching within genres or artists For example if the user is searching for "iPhone" this endpoint can return "cell phones" category. You need to set the used Segmentation the Admin UI in the Scenario settings prior to using this endpoint. The returned segments are sorted by relevance (first segment being the most relevant). It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
SearchItemSegments
} from "recombee-js-api-client";
const const createRequest: CreateRequestFunctioncreateRequest:
type CreateRequestFunction = (options: {
    searchQuery: string;
    isFullScreen?: boolean;
}) => Request
CreateRequestFunction
= ({ searchQuery: stringsearchQuery }) => {
return new
new Batch(requests: Request[], optional?: {
    distinctRecomms?: boolean;
}): Batch
@paramrequests - Array containing the requests.@paramoptional - Optional parameters given as an object (allowed parameters: distinctRecomms).
Batch
(
[ new
new SearchItems(userId: string, searchQuery: string, count: number, optional?: {
    scenario?: string;
    cascadeCreate?: boolean;
    returnProperties?: boolean;
    includedProperties?: string[];
    filter?: string;
    booster?: string;
    logic?: string | object;
    expertSettings?: {
        [key: string]: unknown;
    };
    returnAbGroup?: boolean;
}): SearchItems
@paramuserId - ID of the user for whom personalized search will be performed.@paramsearchQuery - Search query provided by the user. It is used for the full-text search.@paramcount - Number of items to be returned (N for the top-N results).@paramoptional - Optional parameters given as an object.
SearchItems
(userId, searchQuery: stringsearchQuery, 5, {
scenario?: string | undefined
Scenario defines a particular search field in your user interface.
scenario
: "search-items",
cascadeCreate?: boolean | undefined
If the user does not exist in the database, returns a list of non-personalized search results and creates the user in the database. This allows, for example, rotations in the following recommendations for that user, as the user will be already known to the system.
cascadeCreate
: true,
returnProperties?: boolean | undefined
With `returnProperties=true`, property values of the recommended items are returned along with their IDs in a JSON dictionary. The acquired property values can be used to easily display the recommended items to the user.
returnProperties
: true,
}), new
new SearchItemSegments(userId: string, searchQuery: string, count: number, optional?: {
    scenario?: string;
    cascadeCreate?: boolean;
    filter?: string;
    booster?: string;
    logic?: string | object;
    expertSettings?: {
        [key: string]: unknown;
    };
    returnAbGroup?: boolean;
}): SearchItemSegments
@paramuserId - ID of the user for whom personalized search will be performed.@paramsearchQuery - Search query provided by the user. It is used for the full-text search.@paramcount - Number of segments to be returned (N for the top-N results).@paramoptional - Optional parameters given as an object.
SearchItemSegments
(userId, searchQuery: stringsearchQuery, 5, {
scenario?: string | undefined
Scenario defines a particular application of recommendations. It can be, for example, "homepage", "cart", or "emailing".
scenario
: "search-categories",
cascadeCreate?: boolean | undefined
If the user does not exist in the database, returns a list of non-personalized recommendations and creates the user in the database. This allows, for example, rotations in the following recommendations for that user, as the user will be already known to the system.
cascadeCreate
: true,
}), ], { distinctRecomms?: boolean | undefineddistinctRecomms: true, }, ); };
Copy

Please ensure that you provide the user ID, which is typically obtained from your existing user tracking system.

The widget in this example uses the DefaultItem component to render each recommendation in a consistent layout.

The resulting widget is inserted into the element specified by the container field.

Values of the recommended items - such as title, image URL, or link URL - are obtained from the API response and accessed via props.result?.values.

Ensure that returnProperties: true is set in the request, and optionally use includedProperties to control which item properties are returned.

import {
  const QuickSearchWidget: ({ container, ...props }: QuickSearchWidgetOptions) => null | undefined
Quick Search widget
@public
QuickSearchWidget
,
function addRecommIdQueryParam(url: string, recommId: string | undefined): string
Utility function to append `recombee_recomm_id` parameter to an url string. For usage in widget template to construct item link URL.
@public
addRecommIdQueryParam
,
const DefaultInput: ((props: {
    state: QuickSearchWidgetState;
    inputProps?: {
        placeholder?: string;
    };
}) => React.JSX.Element) & {
    ...;
}
DefaultInput
,
const DefaultItem: ((props: {
    href?: string;
    image?: React.ReactNode;
    primaryContent?: React.ReactNode;
    secondaryContent?: React.ReactNode;
    highlightedContent?: React.ReactNode;
}) => React.JSX.Element) & {
    ...;
}
DefaultItem
,
const ItemImage: React.FunctionComponent<ItemImageProps>
Item image component
@public
ItemImage
,
function SearchIcon(): React.JSX.ElementSearchIcon, function CloseIcon(): React.JSX.ElementCloseIcon, const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElementhtml, } from "@recombee/quick-search-widget-js"; import "@recombee/quick-search-widget-js/dist/styles.css"; function QuickSearchWidget({ container, ...props }: QuickSearchWidgetOptions): null | undefined
Quick Search widget
@public
QuickSearchWidget
({
container: string
CSS Selector to target the element where the widget should be inserted.
@public
container
: "#widget-root",
WidgetConfigurationBase<CR extends (...args: any[]) => Request = CreateRequestFunction>.apiClient: ApiClient
Instance of Recombee JS API Client. See {@link file://./#client-initialization Example } .
@public
apiClient
: const apiClient: ApiClientapiClient,
WidgetConfigurationBase<CR extends (...args: any[]) => Request = CreateRequestFunction>.createRequest: CreateRequestFunction
Request factory function. See {@link file://./#client-initialization Quick Example } or visit {@link file:///api API Reference } for overview of available requests.
@public
createRequest
: const createRequest: CreateRequestFunctioncreateRequest,
minSearchCharactersCount: number
Minimum length of search query for search request to be sent.
@public
minSearchCharactersCount
: 3,
desktopMediaQuery: string
CSS media query specifing when the widget should behave as displayed on desktop. By default, widget behaves as mobile-first, filling entire device screen with results dropdown.
@public
desktopMediaQuery
: "(min-width: 1000px)",
type InputComponent: React.FC<InputProps>
Component responsible for rendering the widget input.
@public
InputComponent
: (props: InputPropsprops) =>
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElementhtml`<form className="flex w-[400px] text-[#374040]"> <${
const DefaultInput: ((props: {
    state: QuickSearchWidgetState;
    inputProps?: {
        placeholder?: string;
    };
}) => React.JSX.Element) & {
    ...;
}
DefaultInput
}
state=${props: InputPropsprops.state: QuickSearchWidgetStatestate} inputProps=${{ placeholder: stringplaceholder: `Search for "table"...`, }} /> </form>`, type TriggerComponent: React.FC<TriggerProps>
Component responsible for rendering the widget trigger on mobile devices.
@public
TriggerComponent
: (props: TriggerPropsprops) =>
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElementhtml`<button ...${props: TriggerPropsprops.state: QuickSearchWidgetStatestate.
QuickSearchWidgetState.triggerProps: {
    ref: (element: HTMLElement | null) => void;
    onClick: () => void;
}
Properties to be passed to the trigger button of a mobile widget.
@public
triggerProps
}
className="flex size-[38px] items-center justify-center rounded-sm bg-[#3bc4a1] text-white" > <${function SearchIcon(): React.JSX.ElementSearchIcon} /> </button>`, type DropdownComponent: React.FC<DropdownProps>
Component responsible for rendering the widget dropdown.
@public
DropdownComponent
: (props: DropdownPropsprops) =>
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElementhtml`<div className="mt-1 flex h-full max-h-full min-h-0 flex-col rounded-sm bg-white text-[#374040] shadow-2xl lg:h-auto lg:max-w-[900px] lg:min-w-[600px]" > ${!props: DropdownPropsprops.state: QuickSearchWidgetStatestate.QuickSearchWidgetState.isDesktop: boolean
Indicates that the widget is displayed on desktop device.
@public
isDesktop
&&
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElementhtml`<form className="flex items-center gap-2 p-2"> <div className="flex-grow"> <${
const DefaultInput: ((props: {
    state: QuickSearchWidgetState;
    inputProps?: {
        placeholder?: string;
    };
}) => React.JSX.Element) & {
    ...;
}
DefaultInput
}
state=${props: DropdownPropsprops.state: QuickSearchWidgetStatestate} inputProps=${{ placeholder: stringplaceholder: `Search for "table"...`, }} /> </div> <button ...${props: DropdownPropsprops.state: QuickSearchWidgetStatestate.
QuickSearchWidgetState.closeButtonProps: {
    type: "button";
    onClick: () => void;
    onTouchEnd: () => void;
}
Properties to be passed to the close button of a mobile dropdown.
@public
closeButtonProps
}
className="flex size-[38px] items-center justify-center" > <${function CloseIcon(): React.JSX.ElementCloseIcon} /> </button> </form>`} <div className="flex min-h-0 flex-grow flex-col"> <div className="px-4 py-4 pb-2 text-sm font-semibold text-[#3f91ff]"> Results </div> <div className="overflow-auto p-2"> ${props: DropdownPropsprops.state: QuickSearchWidgetStatestate .
QuickSearchWidgetState.items: (index: number) => {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}[]
Getter for current results of the request batch. The `index` parameter indicates an index of results in the Batch Request for which to return items.
@public
items
(0)
.
Array<{ key: string; id: string; recommId: string; values: { [key: string]: any; }; itemProps: { tabIndex: number; "data-search-result-id"?: string | undefined; onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void; }; }>.map<React.ReactElement<unknown, string | React.JSXElementConstructor<any>>>(callbackfn: (value: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}, index: number, array: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}[]) => React.ReactElement<...>, thisArg?: any): React.ReactElement<...>[]
Calls a defined callback function on each element of an array, and returns an array that contains the results.
@paramcallbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.@paramthisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
map
(
(
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
) =>
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElementhtml`<${
const DefaultItem: ((props: {
    href?: string;
    image?: React.ReactNode;
    primaryContent?: React.ReactNode;
    secondaryContent?: React.ReactNode;
    highlightedContent?: React.ReactNode;
}) => React.JSX.Element) & {
    ...;
}
DefaultItem
}
key=${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.key: stringkey}
href=${function addRecommIdQueryParam(url: string, recommId: string | undefined): string
Utility function to append `recombee_recomm_id` parameter to an url string. For usage in widget template to construct item link URL.
@public
addRecommIdQueryParam
(
`${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.
values: {
    [key: string]: any;
}
values
?.__type[string]: anylink}`,
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.recommId: stringrecommId,
)} image=${const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElementhtml`<${const ItemImage: React.FunctionComponent<ItemImageProps>
Item image component
@public
ItemImage
}
className="size-16 overflow-hidden rounded-lg" src=${`${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.
values: {
    [key: string]: any;
}
values
?.__type[string]: anyimage}`}
width=${600} height=${400} />`} primaryContent=${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.
values: {
    [key: string]: any;
}
values
?.__type[string]: anyproduct_title}
secondaryContent=${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.
values: {
    [key: string]: any;
}
values
?.__type[string]: anycategory_top}
highlightedContent=${`USD ${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.
values: {
    [key: string]: any;
}
values
?.__type[string]: anyprice}`}
...${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.
itemProps: {
    tabIndex: number;
    "data-search-result-id"?: string | undefined;
    onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
}
itemProps
}
/>`, )} </div> </div> </div>`, });
Copy

You can customize the appearance and behavior of the Quick Search Widget by overriding its individual components:

The example also demonstrates how to make the search form submittable to a dedicated results page using a submit button.

import {
  const QuickSearchWidget: ({ container, ...props }: QuickSearchWidgetOptions) => null | undefined
Quick Search widget
@public
QuickSearchWidget
,
function addRecommIdQueryParam(url: string, recommId: string | undefined): string
Utility function to append `recombee_recomm_id` parameter to an url string. For usage in widget template to construct item link URL.
@public
addRecommIdQueryParam
,
function DefaultSpinner(props: {
    className: string;
}): React.JSX.Element
DefaultSpinner
,
const ItemImage: React.FunctionComponent<ItemImageProps>
Item image component
@public
ItemImage
,
function SearchIcon(): React.JSX.ElementSearchIcon, function CloseIcon(): React.JSX.ElementCloseIcon, const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElementhtml, } from "@recombee/quick-search-widget-js"; import "@recombee/quick-search-widget-js/dist/styles.css"; function QuickSearchWidget({ container, ...props }: QuickSearchWidgetOptions): null | undefined
Quick Search widget
@public
QuickSearchWidget
({
container: string
CSS Selector to target the element where the widget should be inserted.
@public
container
: "#widget-root",
WidgetConfigurationBase<CR extends (...args: any[]) => Request = CreateRequestFunction>.apiClient: ApiClient
Instance of Recombee JS API Client. See {@link file://./#client-initialization Example } .
@public
apiClient
: const apiClient: ApiClientapiClient,
WidgetConfigurationBase<CR extends (...args: any[]) => Request = CreateRequestFunction>.createRequest: CreateRequestFunction
Request factory function. See {@link file://./#client-initialization Quick Example } or visit {@link file:///api API Reference } for overview of available requests.
@public
createRequest
: const createRequest: CreateRequestFunctioncreateRequest,
minSearchCharactersCount: number
Minimum length of search query for search request to be sent.
@public
minSearchCharactersCount
: 3,
typingDebounceDuration?: number | undefined
Maximum duration between keystrokes in milliseconds before search request is made.
@public
typingDebounceDuration
: 1000,
desktopMediaQuery: string
CSS media query specifing when the widget should behave as displayed on desktop. By default, widget behaves as mobile-first, filling entire device screen with results dropdown.
@public
desktopMediaQuery
: "(min-width: 1000px)",
type InputComponent: React.FC<InputProps>
Component responsible for rendering the widget input.
@public
InputComponent
: (props: InputPropsprops) =>
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElementhtml`<form method="GET" action="https://example.com/search" target="_blank" className="flex w-[400px] gap-2 text-[#374040]" > <div className="relative flex flex-grow overflow-hidden rounded-lg border border-[#d9dbdb]" > <div className="flex size-[38px] items-center justify-center text-[#737979]" > <${function SearchIcon(): React.JSX.ElementSearchIcon} /> </div> <input name="q" type="text" className="block w-full outline-hidden" placeholder=${`Search for "table"...`} ...${props: InputPropsprops.state: QuickSearchWidgetStatestate.
QuickSearchWidgetState.inputProps: {
    value: string;
    onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
    onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    onClick: () => void;
    ref: (element: HTMLElement | null) => void;
}
Properties to be passed to a input component.
@public
inputProps
}
/>${props: InputPropsprops.state: QuickSearchWidgetStatestate.QuickSearchWidgetState.isLoading: boolean
Boolean flag indicating that a request for new results is in flight.
@public
isLoading
&&
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElementhtml`<${
function DefaultSpinner(props: {
    className: string;
}): React.JSX.Element
DefaultSpinner
}
className="rb:absolute rb:top-2.25 rb:right-2.25 rb:h-5 rb:w-5" />`} </div> <button type="submit" className="rounded-lg bg-[#3f91ff] px-5 py-2.5 text-sm font-medium text-white focus:ring-4 focus:ring-blue-300 focus:outline-hidden" > Search </button> </form>`, type TriggerComponent: React.FC<TriggerProps>
Component responsible for rendering the widget trigger on mobile devices.
@public
TriggerComponent
: (props: TriggerPropsprops) =>
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElementhtml`<button ...${props: TriggerPropsprops.state: QuickSearchWidgetStatestate.
QuickSearchWidgetState.triggerProps: {
    ref: (element: HTMLElement | null) => void;
    onClick: () => void;
}
Properties to be passed to the trigger button of a mobile widget.
@public
triggerProps
}
className="flex size-[38px] items-center justify-center rounded-sm bg-[#3bc4a1] text-white" > <${function SearchIcon(): React.JSX.ElementSearchIcon} /> </button>`, type DropdownComponent: React.FC<DropdownProps>
Component responsible for rendering the widget dropdown.
@public
DropdownComponent
: (props: DropdownPropsprops) =>
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElementhtml`<div className="mt-1 flex h-full max-h-full min-h-0 flex-col rounded-sm bg-white text-[#374040] shadow-2xl lg:h-auto lg:max-w-[900px] lg:min-w-[600px]" > ${!props: DropdownPropsprops.state: QuickSearchWidgetStatestate.QuickSearchWidgetState.isDesktop: boolean
Indicates that the widget is displayed on desktop device.
@public
isDesktop
&&
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElementhtml`<form className="flex items-center gap-2 p-2"> <div className="flex-grow"> <div className="relative flex flex-grow overflow-hidden rounded-lg border border-[#d9dbdb]" > <div className="flex size-[42px] items-center justify-center text-[#737979]" > <${function SearchIcon(): React.JSX.ElementSearchIcon} /> </div> <input type="text" className="block w-full outline-hidden" placeholder="Search in docs..." ...${props: DropdownPropsprops.state: QuickSearchWidgetStatestate.
QuickSearchWidgetState.inputProps: {
    value: string;
    onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
    onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    onClick: () => void;
    ref: (element: HTMLElement | null) => void;
}
Properties to be passed to a input component.
@public
inputProps
}
/>${props: DropdownPropsprops.state: QuickSearchWidgetStatestate.QuickSearchWidgetState.isLoading: boolean
Boolean flag indicating that a request for new results is in flight.
@public
isLoading
&&
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElementhtml`<div className="absolute top-2.5 right-2.5 h-5 w-5 animate-spin rounded-full border-2 border-dashed border-current text-[#d9dbdb] [--animate-spin:spin_3s_linear_infinite]" />`} </div> </div> <button ...${props: DropdownPropsprops.state: QuickSearchWidgetStatestate.
QuickSearchWidgetState.closeButtonProps: {
    type: "button";
    onClick: () => void;
    onTouchEnd: () => void;
}
Properties to be passed to the close button of a mobile dropdown.
@public
closeButtonProps
}
className="flex size-[38px] items-center justify-center" > <${function CloseIcon(): React.JSX.ElementCloseIcon} /> </button> </form>`} <div className="flex min-h-0 flex-grow flex-col"> <div className="px-4 py-4 pb-2 text-sm font-semibold text-[#3f91ff]"> Results </div> <div className="overflow-auto p-2"> ${props: DropdownPropsprops.state: QuickSearchWidgetStatestate.
QuickSearchWidgetState.items: (index: number) => {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}[]
Getter for current results of the request batch. The `index` parameter indicates an index of results in the Batch Request for which to return items.
@public
items
(0).
Array<{ key: string; id: string; recommId: string; values: { [key: string]: any; }; itemProps: { tabIndex: number; "data-search-result-id"?: string | undefined; onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void; }; }>.map<React.ReactElement<unknown, string | React.JSXElementConstructor<any>>>(callbackfn: (value: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}, index: number, array: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}[]) => React.ReactElement<...>, thisArg?: any): React.ReactElement<...>[]
Calls a defined callback function on each element of an array, and returns an array that contains the results.
@paramcallbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.@paramthisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
map
(
(
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
) =>
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElementhtml`<a key=${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.key: stringkey}
href=${function addRecommIdQueryParam(url: string, recommId: string | undefined): string
Utility function to append `recombee_recomm_id` parameter to an url string. For usage in widget template to construct item link URL.
@public
addRecommIdQueryParam
(
`${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.
values: {
    [key: string]: any;
}
values
?.__type[string]: anylink}`,
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.recommId: stringrecommId,
)} ...${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.
itemProps: {
    tabIndex: number;
    "data-search-result-id"?: string | undefined;
    onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
}
itemProps
}
className="flex items-center gap-4 rounded-sm p-2 outline-hidden hover:bg-[#f7f7f7] focus:bg-[#f7f7f7]" ><div> <${const ItemImage: React.FunctionComponent<ItemImageProps>
Item image component
@public
ItemImage
}
className="size-16 overflow-hidden rounded-lg" src=${`${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.
values: {
    [key: string]: any;
}
values
?.__type[string]: anyimage}`}
width=${600} height=${400} /> </div> <div className="rb:flex-grow"> <div className="rb:font-semibold rb:text-nowrap rb:text-ellipsis rb:overflow-hidden" > ${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.
values: {
    [key: string]: any;
}
values
?.__type[string]: anyproduct_title}
</div> <div className="rb:text-[#737979] rb:text-nowrap rb:text-ellipsis rb:overflow-hidden" > ${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.
values: {
    [key: string]: any;
}
values
?.__type[string]: anycategory}
</div> </div> <div className="rb:font-bold rb:text-[#3f91ff] rb:text-nowrap rb:text-ellipsis rb:overflow-hidden" > ${`USD ${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.
values: {
    [key: string]: any;
}
values
?.__type[string]: anyprice}`}
</div></a >`, )} </div> </div> </div>`, });
Copy

You can use the Quick Search Widget to display multiple types of results. For example, showing not only items but also categories or brands using the Search Item Segments requests.

All search requests are sent together in a single Batch request.

import {
  const QuickSearchWidget: ({ container, ...props }: QuickSearchWidgetOptions) => null | undefined
Quick Search widget
@public
QuickSearchWidget
,
function addRecommIdQueryParam(url: string, recommId: string | undefined): string
Utility function to append `recombee_recomm_id` parameter to an url string. For usage in widget template to construct item link URL.
@public
addRecommIdQueryParam
,
const DefaultInput: ((props: {
    state: QuickSearchWidgetState;
    inputProps?: {
        placeholder?: string;
    };
}) => React.JSX.Element) & {
    ...;
}
DefaultInput
,
const DefaultItem: ((props: {
    href?: string;
    image?: React.ReactNode;
    primaryContent?: React.ReactNode;
    secondaryContent?: React.ReactNode;
    highlightedContent?: React.ReactNode;
}) => React.JSX.Element) & {
    ...;
}
DefaultItem
,
const ItemImage: React.FunctionComponent<ItemImageProps>
Item image component
@public
ItemImage
,
function SearchIcon(): React.JSX.ElementSearchIcon, function CloseIcon(): React.JSX.ElementCloseIcon, const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElementhtml, } from "@recombee/quick-search-widget-js"; import "@recombee/quick-search-widget-js/dist/styles.css"; const const createRequest: CreateRequestFunctioncreateRequest:
type CreateRequestFunction = (options: {
    searchQuery: string;
    isFullScreen?: boolean;
}) => Request
CreateRequestFunction
= ({ searchQuery: stringsearchQuery }) => {
return new
new Batch(requests: Request[], optional?: {
    distinctRecomms?: boolean;
}): Batch
@paramrequests - Array containing the requests.@paramoptional - Optional parameters given as an object (allowed parameters: distinctRecomms).
Batch
(
[ new
new SearchItems(userId: string, searchQuery: string, count: number, optional?: {
    scenario?: string;
    cascadeCreate?: boolean;
    returnProperties?: boolean;
    includedProperties?: string[];
    filter?: string;
    booster?: string;
    logic?: string | object;
    expertSettings?: {
        [key: string]: unknown;
    };
    returnAbGroup?: boolean;
}): SearchItems
@paramuserId - ID of the user for whom personalized search will be performed.@paramsearchQuery - Search query provided by the user. It is used for the full-text search.@paramcount - Number of items to be returned (N for the top-N results).@paramoptional - Optional parameters given as an object.
SearchItems
("userId", searchQuery: stringsearchQuery, 5, {
scenario?: string | undefined
Scenario defines a particular search field in your user interface.
scenario
: "search",
cascadeCreate?: boolean | undefined
If the user does not exist in the database, returns a list of non-personalized search results and creates the user in the database. This allows, for example, rotations in the following recommendations for that user, as the user will be already known to the system.
cascadeCreate
: true,
returnProperties?: boolean | undefined
With `returnProperties=true`, property values of the recommended items are returned along with their IDs in a JSON dictionary. The acquired property values can be used to easily display the recommended items to the user.
returnProperties
: true,
}), new
new SearchItemSegments(userId: string, searchQuery: string, count: number, optional?: {
    scenario?: string;
    cascadeCreate?: boolean;
    filter?: string;
    booster?: string;
    logic?: string | object;
    expertSettings?: {
        [key: string]: unknown;
    };
    returnAbGroup?: boolean;
}): SearchItemSegments
@paramuserId - ID of the user for whom personalized search will be performed.@paramsearchQuery - Search query provided by the user. It is used for the full-text search.@paramcount - Number of segments to be returned (N for the top-N results).@paramoptional - Optional parameters given as an object.
SearchItemSegments
("userId", searchQuery: stringsearchQuery, 5, {
scenario?: string | undefined
Scenario defines a particular application of recommendations. It can be, for example, "homepage", "cart", or "emailing".
scenario
: "search-brands",
cascadeCreate?: boolean | undefined
If the user does not exist in the database, returns a list of non-personalized recommendations and creates the user in the database. This allows, for example, rotations in the following recommendations for that user, as the user will be already known to the system.
cascadeCreate
: true,
}), ], { distinctRecomms?: boolean | undefineddistinctRecomms: true, }, ); }; function QuickSearchWidget({ container, ...props }: QuickSearchWidgetOptions): null | undefined
Quick Search widget
@public
QuickSearchWidget
({
container: string
CSS Selector to target the element where the widget should be inserted.
@public
container
: "#widget-root",
WidgetConfigurationBase<CR extends (...args: any[]) => Request = CreateRequestFunction>.apiClient: ApiClient
Instance of Recombee JS API Client. See {@link file://./#client-initialization Example } .
@public
apiClient
: const apiClient: ApiClientapiClient,
WidgetConfigurationBase<CR extends (...args: any[]) => Request = CreateRequestFunction>.createRequest: CreateRequestFunction
Request factory function. See {@link file://./#client-initialization Quick Example } or visit {@link file:///api API Reference } for overview of available requests.
@public
createRequest
: const createRequest: CreateRequestFunctioncreateRequest,
minSearchCharactersCount: number
Minimum length of search query for search request to be sent.
@public
minSearchCharactersCount
: 3,
primaryResultsIndex?: number | undefined
Index of request in a batch from which the results are considered to be navigable by arrow keys.
@public
primaryResultsIndex
: 0,
desktopMediaQuery: string
CSS media query specifing when the widget should behave as displayed on desktop. By default, widget behaves as mobile-first, filling entire device screen with results dropdown.
@public
desktopMediaQuery
: "(min-width: 1000px)",
type InputComponent: React.FC<InputProps>
Component responsible for rendering the widget input.
@public
InputComponent
: (props: InputPropsprops) =>
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElementhtml`<form className="flex w-[400px] text-[#374040]"> <${
const DefaultInput: ((props: {
    state: QuickSearchWidgetState;
    inputProps?: {
        placeholder?: string;
    };
}) => React.JSX.Element) & {
    ...;
}
DefaultInput
}
state=${props: InputPropsprops.state: QuickSearchWidgetStatestate} inputProps=${{ placeholder: stringplaceholder: `Search for "table"...`, }} /> </form>`, type TriggerComponent: React.FC<TriggerProps>
Component responsible for rendering the widget trigger on mobile devices.
@public
TriggerComponent
: (props: TriggerPropsprops) =>
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElementhtml`<button ...${props: TriggerPropsprops.state: QuickSearchWidgetStatestate.
QuickSearchWidgetState.triggerProps: {
    ref: (element: HTMLElement | null) => void;
    onClick: () => void;
}
Properties to be passed to the trigger button of a mobile widget.
@public
triggerProps
}
className="flex size-[38px] items-center justify-center rounded-sm bg-[#3bc4a1] text-white" > <${function SearchIcon(): React.JSX.ElementSearchIcon} /> </button>`, type DropdownComponent: React.FC<DropdownProps>
Component responsible for rendering the widget dropdown.
@public
DropdownComponent
: (props: DropdownPropsprops) =>
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElementhtml`<div className="mt-1 flex h-full max-h-full min-h-0 flex-col rounded-sm bg-white text-[#374040] shadow-2xl lg:h-auto lg:max-w-[900px] lg:min-w-[600px]" > ${!props: DropdownPropsprops.state: QuickSearchWidgetStatestate.QuickSearchWidgetState.isDesktop: boolean
Indicates that the widget is displayed on desktop device.
@public
isDesktop
&&
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElementhtml`<form className="flex items-center gap-2 p-2"> <div className="flex-grow"> <${
const DefaultInput: ((props: {
    state: QuickSearchWidgetState;
    inputProps?: {
        placeholder?: string;
    };
}) => React.JSX.Element) & {
    ...;
}
DefaultInput
}
state=${props: DropdownPropsprops.state: QuickSearchWidgetStatestate} inputProps=${{ placeholder: stringplaceholder: `Search for "table"...`, }} /> </div> <button ...${props: DropdownPropsprops.state: QuickSearchWidgetStatestate.
QuickSearchWidgetState.closeButtonProps: {
    type: "button";
    onClick: () => void;
    onTouchEnd: () => void;
}
Properties to be passed to the close button of a mobile dropdown.
@public
closeButtonProps
}
className="flex size-[38px] items-center justify-center" > <${function CloseIcon(): React.JSX.ElementCloseIcon} /> </button> </form>`} <div className="flex"> <div className="flex min-h-0 flex-col"> <div className="px-4 py-4 pb-2 text-sm font-semibold text-[#3f91ff]"> Segments </div> <div className="overflow-auto p-2"> ${props: DropdownPropsprops.state: QuickSearchWidgetStatestate.
QuickSearchWidgetState.items: (index: number) => {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}[]
Getter for current results of the request batch. The `index` parameter indicates an index of results in the Batch Request for which to return items.
@public
items
(1).
Array<{ key: string; id: string; recommId: string; values: { [key: string]: any; }; itemProps: { tabIndex: number; "data-search-result-id"?: string | undefined; onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void; }; }>.map<React.ReactElement<unknown, string | React.JSXElementConstructor<any>>>(callbackfn: (value: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}, index: number, array: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}[]) => React.ReactElement<...>, thisArg?: any): React.ReactElement<...>[]
Calls a defined callback function on each element of an array, and returns an array that contains the results.
@paramcallbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.@paramthisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
map
(
(
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
) =>
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElementhtml`<a key=${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.key: stringkey}
href=${function addRecommIdQueryParam(url: string, recommId: string | undefined): string
Utility function to append `recombee_recomm_id` parameter to an url string. For usage in widget template to construct item link URL.
@public
addRecommIdQueryParam
(
`${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.
values: {
    [key: string]: any;
}
values
?.__type[string]: anylink}`,
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.recommId: stringrecommId,
)} ...${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.
itemProps: {
    tabIndex: number;
    "data-search-result-id"?: string | undefined;
    onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
}
itemProps
}
className="flex items-center gap-2 rounded-sm p-2 text-nowrap outline-hidden hover:bg-[#f7f7f7] focus:bg-[#f7f7f7]" ><div className="flex-grow"> <div className="font-semibold">${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.id: stringid}</div>
</div></a >`, )} </div> </div> <div className="flex min-h-0 flex-grow flex-col"> <div className="px-4 py-4 pb-2 text-sm font-semibold text-[#3f91ff]"> Results </div> <div className="overflow-auto p-2"> ${props: DropdownPropsprops.state: QuickSearchWidgetStatestate .
QuickSearchWidgetState.items: (index: number) => {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}[]
Getter for current results of the request batch. The `index` parameter indicates an index of results in the Batch Request for which to return items.
@public
items
(0)
.
Array<{ key: string; id: string; recommId: string; values: { [key: string]: any; }; itemProps: { tabIndex: number; "data-search-result-id"?: string | undefined; onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void; }; }>.map<React.ReactElement<unknown, string | React.JSXElementConstructor<any>>>(callbackfn: (value: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}, index: number, array: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}[]) => React.ReactElement<...>, thisArg?: any): React.ReactElement<...>[]
Calls a defined callback function on each element of an array, and returns an array that contains the results.
@paramcallbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.@paramthisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
map
(
(
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
) =>
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElementhtml`<${
const DefaultItem: ((props: {
    href?: string;
    image?: React.ReactNode;
    primaryContent?: React.ReactNode;
    secondaryContent?: React.ReactNode;
    highlightedContent?: React.ReactNode;
}) => React.JSX.Element) & {
    ...;
}
DefaultItem
}
key=${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.key: stringkey}
href=${function addRecommIdQueryParam(url: string, recommId: string | undefined): string
Utility function to append `recombee_recomm_id` parameter to an url string. For usage in widget template to construct item link URL.
@public
addRecommIdQueryParam
(
`${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.
values: {
    [key: string]: any;
}
values
?.__type[string]: anylink}`,
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.recommId: stringrecommId,
)} image=${const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElementhtml`<${const ItemImage: React.FunctionComponent<ItemImageProps>
Item image component
@public
ItemImage
}
className="size-16 overflow-hidden rounded-lg" src=${`${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.
values: {
    [key: string]: any;
}
values
?.__type[string]: anyimage}`}
width=${600} height=${400} />`} primaryContent=${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.
values: {
    [key: string]: any;
}
values
?.__type[string]: anyproduct_title}
secondaryContent=${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.
values: {
    [key: string]: any;
}
values
?.__type[string]: anycategory_top}
highlightedContent=${`USD ${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.
values: {
    [key: string]: any;
}
values
?.__type[string]: anyprice}`}
...${
item: {
    key: string;
    id: string;
    recommId: string;
    values: {
        [key: string]: any;
    };
    itemProps: {
        tabIndex: number;
        "data-search-result-id"?: string | undefined;
        onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
    };
}
item
.
itemProps: {
    tabIndex: number;
    "data-search-result-id"?: string | undefined;
    onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
}
itemProps
}
/>`, )} </div> </div> </div> </div>`, });
Copy

API Reference

const

Quick Search widget

type

Quick Search widget options

Properties

string

CSS Selector to target the element where the widget should be inserted.


ApiClient

Instance of Recombee JS API Client. See Example.


QuickSearchCreateRequestFunction

Request factory function. See Quick Example or visit API Reference for overview of available requests.


WidgetRecommResponseCallback | undefined

Callback function allowing to intercept and inspect recommendation request+response made by widget.

import React from "react";
import { const CarouselWidget: ({ container, ...props }: CarouselWidgetOptions) => CarouselWidgetState | null | undefined
Carousel Widget initialization function
@public
CarouselWidget
} from "@recombee/carousel-widget-js";
function CarouselWidget({ container, ...props }: CarouselWidgetOptions): CarouselWidgetState | null | undefined
Carousel Widget initialization function
@public
CarouselWidget
({
// ...ommited code... WidgetConfigurationBase<CreateRequestFunction>.onRecommResponse?: WidgetRecommResponseCallback | undefined
Callback function allowing to intercept and inspect recommendation request+response made by widget. ```tsx|-react import React from "react"; import { CarouselWidget } from "@recombee/carousel-widget-react"; //
@noErrors: 2739 2345 <CarouselWidget // ...ommited code... onRecommResponse={({ recombeeRequest, recombeeResponse }) => { // use data from request and response for any purpose, i.e. internal tracking }} />; ``` ```ts|-js import React from "react"; import { CarouselWidget } from "@recombee/carousel-widget-js"; //@noErrors: 2739 2345 CarouselWidget({ // ...ommited code... onRecommResponse: ({ recombeeRequest, recombeeResponse }) => { // use data from request and response for any purpose, i.e. internal tracking }, }); ```@public
onRecommResponse
: ({ recombeeRequest: RequestrecombeeRequest, recombeeResponse: anyrecombeeResponse }) => {
// use data from request and response for any purpose, i.e. internal tracking }, });
Copy

string | undefined

String to be prefilled into the search input


number

Minimum length of search query for search request to be sent.


number | undefined

Maximum duration between keystrokes in milliseconds before search request is made.


number | undefined

Index of request in a batch from which the results are considered to be navigable by arrow keys.


FC<InputProps>

Component responsible for rendering the widget input.


FC<TriggerProps>

Component responsible for rendering the widget trigger on mobile devices.


FC<DropdownProps>

Component responsible for rendering the widget dropdown.


string

CSS media query specifing when the widget should behave as displayed on desktop. By default, widget behaves as mobile-first, filling entire device screen with results dropdown.


type

Quick Search component configuration options

Properties

ApiClient

Instance of Recombee JS API Client. See Example.


QuickSearchCreateRequestFunction

Request factory function. See Quick Example or visit API Reference for overview of available requests.


WidgetRecommResponseCallback | undefined

Callback function allowing to intercept and inspect recommendation request+response made by widget.

import React from "react";
import { const CarouselWidget: ({ container, ...props }: CarouselWidgetOptions) => CarouselWidgetState | null | undefined
Carousel Widget initialization function
@public
CarouselWidget
} from "@recombee/carousel-widget-js";
function CarouselWidget({ container, ...props }: CarouselWidgetOptions): CarouselWidgetState | null | undefined
Carousel Widget initialization function
@public
CarouselWidget
({
// ...ommited code... WidgetConfigurationBase<CreateRequestFunction>.onRecommResponse?: WidgetRecommResponseCallback | undefined
Callback function allowing to intercept and inspect recommendation request+response made by widget. ```tsx|-react import React from "react"; import { CarouselWidget } from "@recombee/carousel-widget-react"; //
@noErrors: 2739 2345 <CarouselWidget // ...ommited code... onRecommResponse={({ recombeeRequest, recombeeResponse }) => { // use data from request and response for any purpose, i.e. internal tracking }} />; ``` ```ts|-js import React from "react"; import { CarouselWidget } from "@recombee/carousel-widget-js"; //@noErrors: 2739 2345 CarouselWidget({ // ...ommited code... onRecommResponse: ({ recombeeRequest, recombeeResponse }) => { // use data from request and response for any purpose, i.e. internal tracking }, }); ```@public
onRecommResponse
: ({ recombeeRequest: RequestrecombeeRequest, recombeeResponse: anyrecombeeResponse }) => {
// use data from request and response for any purpose, i.e. internal tracking }, });
Copy

string | undefined

String to be prefilled into the search input


number

Minimum length of search query for search request to be sent.


number | undefined

Maximum duration between keystrokes in milliseconds before search request is made.


number | undefined

Index of request in a batch from which the results are considered to be navigable by arrow keys.


FC<InputProps>

Component responsible for rendering the widget input.


FC<TriggerProps>

Component responsible for rendering the widget trigger on mobile devices.


FC<DropdownProps>

Component responsible for rendering the widget dropdown.


string

CSS media query specifing when the widget should behave as displayed on desktop. By default, widget behaves as mobile-first, filling entire device screen with results dropdown.


class

Class exposing quick search widget state for use in custom templates

Properties

boolean

Indicates that the widget is displayed on desktop device.


() => void

Resets the widget to its initial state


{ value: string; onChange: (event: ChangeEvent<HTMLInputElement>) => void; onKeyDown: (event: KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void; onClick: () => void; ref: (element: HTMLElement | null) => void; }

Properties to be passed to a input component.


{ ref: (element: HTMLElement | null) => void; onClick: () => void; }

Properties to be passed to the trigger button of a mobile widget.


{ type: "button"; onClick: () => void; onTouchEnd: () => void; }

Properties to be passed to the close button of a mobile dropdown.


(index: number) => { key: string; id: string; recommId: string; values: { [key: string]: any; }; itemProps: { tabIndex: number; "data-search-result-id"?: string | undefined; onKeyDown: (event: KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void; }; }[]

Getter for current results of the request batch. The index parameter indicates an index of results in the Batch Request for which to return items.


boolean

Boolean flag indicating that the widget dropdown is open.


boolean

Boolean flag indicating that a request for new results is in flight.


const

Item image component

type

Item Image properties

Properties

string | null | undefined

Image URL


string | undefined

URL of an image to display when the main image could not be loaded.


string | undefined

Image wrapper class name


string | undefined

Image class name


number | undefined

Image width in pixels


number | undefined

Image height in pixels


"top" | "center" | "bottom" | undefined

Image vertical alignment


"center" | "left" | "right" | undefined

Image horizontal alignment


"cover" | "scale_down" | undefined

Image fitting algorithm


function

Utility function to append recombee_recomm_id parameter to an url string. For usage in widget template to construct item link URL.

© Copyright 2025, Recombee s.r.o
docs.recombee.com