Skip to content

fix(algolia): properly forward placeholder/translations to DocSearch components #10799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,36 @@

declare module '@docusaurus/theme-search-algolia' {
import type {DeepPartial} from 'utility-types';
import type {DocSearchProps} from '@docsearch/react';

export type ThemeConfig = {
algolia: {
contextualSearch: boolean;
externalUrlRegex?: string;
appId: string;
apiKey: string;
indexName: string;
searchParameters: {[key: string]: unknown};
searchPagePath: string | false | null;
replaceSearchResultPathname?: {
from: string;
to: string;
};
insights?: boolean;
// DocSearch props that Docusaurus exposes directly through props forwarding
type DocusaurusDocSearchProps = Pick<
DocSearchProps,
| 'appId'
| 'apiKey'
| 'indexName'
| 'placeholder'
| 'translations'
| 'searchParameters'
| 'insights'
| 'initialQuery'
>;

type ThemeConfigAlgolia = DocusaurusDocSearchProps & {
// Docusaurus custom options, not coming from DocSearch
contextualSearch: boolean;
externalUrlRegex?: string;
searchPagePath: string | false | null;
replaceSearchResultPathname?: {
from: string;
to: string;
};
};

export type ThemeConfig = DocusaurusDocSearchProps & {
algolia: ThemeConfigAlgolia;
};

export type UserThemeConfig = DeepPartial<ThemeConfig>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ function DocSearch({
onMouseOver={importDocSearchModalIfNeeded}
onClick={openModal}
ref={searchButtonRef}
translations={translations.button}
translations={props.translations?.button ?? translations.button}
/>

{isOpen &&
Expand All @@ -260,10 +260,10 @@ function DocSearch({
{...(props.searchPagePath && {
resultsFooterComponent,
})}
placeholder={translations.placeholder}
{...props}
translations={props.translations?.modal ?? translations.modal}
searchParameters={searchParameters}
placeholder={translations.placeholder}
translations={translations.modal}
/>,
searchContainer.current,
)}
Expand Down
Loading