Skip to main content
This widget is and is subject to change in minor versions.
For more information, see Agent Studio.
Signature

Import

About this widget

Use the chatTrigger widget to render a button that opens the chat widget’s overlay. By default, it’s a floating action button anchored to the bottom-right of the viewport. The chat widget doesn’t render a way to open it on its own, so pair it with chatTrigger unless you provide another entry point such as AI mode on a searchBox or an inline layout. See also: Agent Studio

Examples

JavaScript

Options

string | HTMLElement
required
The CSS Selector or HTMLElement to insert the widget into.
boolean
default:true
Whether to render the button as a floating action button anchored to the bottom-right of the viewport. Set it to false to render an inline button that flows with surrounding content.
JavaScript
object
The templates to customize parts of the widget.
  • layout. Template for the trigger button layout. Receives the button props, including open, onClick, and toggleIconComponent.
  • icon. Template for the trigger button icon. Receives a parameter containing { isOpen: boolean } for conditional rendering.
JavaScript
object
The CSS classes you can override and pass to the widget’s elements. It’s useful to style widgets with class-based CSS frameworks like Bootstrap or Tailwind CSS.
  • button. CSS class to add to the button.
JavaScript

HTML output

HTML
When the chat is open, the button also gets the ais-ChatToggleButton--open class.

Customize the UI with connectChatTrigger

If you want to create your own UI of the chatTrigger widget, you can use connectors. Use it for entry points the built-in button doesn’t cover: a hero call to action, a keyboard shortcut, or an “ask about this product” link. They all go through the same connector as the chatTrigger widget, so the chat widget’s entry-point validation counts them and you don’t need to also add chatTrigger. To use connectChatTrigger, you can import it with the declaration relevant to how you installed InstantSearch.js.
Then it’s a 3-step process:
JavaScript

Create a render function

This rendering function is called before the first search (init lifecycle step) and each time results come back from Algolia (render lifecycle step).
JavaScript

Render options

boolean
Whether the chat panel is open.
() => void
Opens the chat panel when it’s closed, and closes it when it’s open.
(options?: OpenChatOptions) => boolean
Opens the chat panel, and submits a message to it when you pass one. Returns true when it submitted a message.Without a message, it opens the panel and focuses its input. With a message, it submits the message unless the chat is already busy, so check isChatBusy before you call it.options accepts:
  • message. Text to submit as a user message. Empty or whitespace-only values open the chat without sending anything.
  • referer. The entry point the request came from, sent as the x-algolia-referer header so the backend can attribute the traffic. The built-in values are 'ai-mode', 'prompt-suggestions-widget', and 'prompt-suggestions-autocomplete'. Pass your own string for a custom entry point.
  • turnContext. A flat object of string values attached to the outgoing message, which grounds the answer in the page the shopper triggered it from. The context option on the chat widget takes precedence when it’s set.
boolean
Whether the chat is submitting or streaming a message, and so can’t accept a new one. It’s false until the chat has initialized.

Create and instantiate the custom widget

First, create your custom widgets using a rendering function. Then, instantiate them with parameters. You can pass two kinds of parameters:
  • Instance parameters. Predefined options that configure Algolia’s behavior.
  • Custom parameters. Parameters you define to make the widget reusable and adaptable.
Inside the renderFunction, both instance and custom parameters are accessible through connector.widgetParams.
JavaScript

Instance options

connectChatTrigger doesn’t take any instance options, so pass anything your render function needs through a closure.

Full example

JavaScript
Last modified on August 27, 2026