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' {
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>;
}

View file

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