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<
contextualSearch: boolean; DocSearchProps,
externalUrlRegex?: string; | 'appId'
appId: string; | 'apiKey'
apiKey: string; | 'indexName'
indexName: string; | 'placeholder'
searchParameters: {[key: string]: unknown}; | 'translations'
searchPagePath: string | false | null; | 'searchParameters'
replaceSearchResultPathname?: { | 'insights'
from: string; | 'initialQuery'
to: string; >;
};
insights?: boolean; 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>; 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,
)} )}