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

This commit is contained in:
Sébastien Lorber 2024-12-26 16:30:23 +01:00 committed by GitHub
parent e7a8c9db82
commit e8ad3923ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 18 deletions

View file

@ -7,23 +7,36 @@
declare module '@docusaurus/theme-search-algolia' { declare module '@docusaurus/theme-search-algolia' {
import type {DeepPartial} from 'utility-types'; import type {DeepPartial} from 'utility-types';
import type {DocSearchProps} from '@docsearch/react';
export type ThemeConfig = { // DocSearch props that Docusaurus exposes directly through props forwarding
algolia: { type DocusaurusDocSearchProps = Pick<
DocSearchProps,
| 'appId'
| 'apiKey'
| 'indexName'
| 'placeholder'
| 'translations'
| 'searchParameters'
| 'insights'
| 'initialQuery'
>;
type ThemeConfigAlgolia = DocusaurusDocSearchProps & {
// Docusaurus custom options, not coming from DocSearch
contextualSearch: boolean; contextualSearch: boolean;
externalUrlRegex?: string; externalUrlRegex?: string;
appId: string;
apiKey: string;
indexName: string;
searchParameters: {[key: string]: unknown};
searchPagePath: string | false | null; searchPagePath: string | false | null;
replaceSearchResultPathname?: { replaceSearchResultPathname?: {
from: string; from: string;
to: string; to: string;
}; };
insights?: boolean;
}; };
export type ThemeConfig = DocusaurusDocSearchProps & {
algolia: ThemeConfigAlgolia;
}; };
export type UserThemeConfig = DeepPartial<ThemeConfig>; export type UserThemeConfig = DeepPartial<ThemeConfig>;
} }

View file

@ -242,7 +242,7 @@ function DocSearch({
onMouseOver={importDocSearchModalIfNeeded} onMouseOver={importDocSearchModalIfNeeded}
onClick={openModal} onClick={openModal}
ref={searchButtonRef} ref={searchButtonRef}
translations={translations.button} translations={props.translations?.button ?? translations.button}
/> />
{isOpen && {isOpen &&
@ -260,10 +260,10 @@ function DocSearch({
{...(props.searchPagePath && { {...(props.searchPagePath && {
resultsFooterComponent, resultsFooterComponent,
})} })}
{...props}
searchParameters={searchParameters}
placeholder={translations.placeholder} placeholder={translations.placeholder}
translations={translations.modal} {...props}
translations={props.translations?.modal ?? translations.modal}
searchParameters={searchParameters}
/>, />,
searchContainer.current, searchContainer.current,
)} )}