Skip to main content
The DocSearch component is the primary React component for integrating Algolia DocSearch into your application. It renders a search button and modal interface for searching documentation.

Import

Usage

Props

string
required
Algolia application ID used by the search client.
string
required
Public API key with search permissions for the index.
string
deprecated
Name of the Algolia index to query.Deprecated: Use indices property instead.
Array<DocSearchIndex | string>
List of indices and optional search parameters to be used for search.Each item can be a string (index name) or an object with:
  • name (string): Index name
  • searchParameters (SearchParamsObject): Optional search parameters for this index
DocSearchAskAi | string
Configuration or assistant ID to enable Ask AI mode. Pass a string assistant ID or a full config object.When provided as an object, supports:
  • assistantId (string, required): The assistant ID to use
  • indexName (string): Index name for Ask AI (defaults to main index)
  • apiKey (string): API key for Ask AI (defaults to main apiKey)
  • appId (string): App ID for Ask AI (defaults to main appId)
  • suggestedQuestions (boolean): Enable suggested questions display
  • searchParameters (AskAiSearchParameters): Search parameters for AI context retrieval
  • agentStudio (boolean): Experimental Agent Studio backend support
(initialMessage: InitialAskAiMessage) => boolean | void
Intercept Ask AI requests (e.g., submitting a prompt or selecting a suggested question).Return true to prevent the default modal Ask AI flow (no toggle, no sendMessage). Useful to route Ask AI into a different UI (e.g., @docsearch/sidepanel-js) without flicker.
'light' | 'dark'
Theme overrides applied to the modal and related components.
string
Placeholder text for the search input.
SearchParamsObject
deprecated
Additional Algolia search parameters to merge into each query.Deprecated: Use indices property instead.
number
Maximum number of hits to display per source/group.
(items: DocSearchHit[]) => DocSearchHit[]
Hook to post-process hits before rendering. Receives an array of hits and should return the transformed array.
function
Custom component to render an individual hit.Signature: (props: { hit: InternalDocSearchHit | StoredDocSearchHit; children: React.ReactNode }, helpers?: { html: (template: TemplateStringsArray, ...values: any[]) => any }) => JSX.ElementSupports multiple template patterns:
  • HTML strings with html helper: (props, { html }) => html\
  • JSX templates: (props) => <div>...</div>
  • Function-based templates
Custom component rendered at the bottom of the results panel.Signature: (props: { state: AutocompleteState<InternalDocSearchHit> }, helpers?: { html: (template: TemplateStringsArray, ...values: any[]) => any }) => JSX.Element | nullSupports the same template patterns as hitComponent.
(searchClient: DocSearchTransformClient) => DocSearchTransformClient
Hook to wrap or modify the Algolia search client. Use this to add custom headers, middleware, or other client modifications.
boolean
default:"false"
Disable storage and usage of recent and favorite searches.
string
Query string to prefill when opening the modal.
AutocompleteOptions['navigator']
Custom navigator for controlling link navigation. Useful for client-side routing.
DocSearchTranslations
Localized strings for the button and modal UI.Object with optional properties:
  • button (ButtonTranslations): Button translations
  • modal (ModalTranslations): Modal translations
({ query }: { query: string }) => string
Builds a URL to report missing results for a given query. The returned URL is used in the “no results” screen.
AutocompleteOptions['insights']
Insights client integration options to send analytics events.
DocumentFragment | Element
The container element where the modal should be portaled to. Defaults to document.body.
number
default:"7"
Limit of how many recent searches should be saved/displayed.
number
default:"4"
Limit of how many recent searches should be saved/displayed when there are favorited searches.
DocSearchModalShortcuts
default:"{ 'Ctrl/Cmd+K': true, '/': true }"
Configuration for keyboard shortcuts. Allows enabling/disabling specific shortcuts.Object with optional properties:
  • 'Ctrl/Cmd+K' (boolean): Enable/disable Ctrl/Cmd+K shortcut
  • '/' (boolean): Enable/disable forward slash shortcut

Ref Methods

When using React.forwardRef, the component exposes a DocSearchRef object with methods for programmatic control:
function
Opens the search modal programmatically.
function
Closes the search modal programmatically.

Example with Ref

Types

DocSearchIndex

DocSearchAskAi

DocSearchTranslations