Skip to content

Commit

Permalink
fix(algolia): properly forward placeholder/translations to DocSearch …
Browse files Browse the repository at this point in the history
…components (facebook#10799)
  • Loading branch information
slorber authored Dec 26, 2024
1 parent e7a8c9d commit e8ad392
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
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

0 comments on commit e8ad392

Please sign in to comment.