Skip to content

Commit e8ad392

Browse files
authored
fix(algolia): properly forward placeholder/translations to DocSearch components (#10799)
1 parent e7a8c9d commit e8ad392

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

packages/docusaurus-theme-search-algolia/src/theme-search-algolia.d.ts

+27-14
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,36 @@
77

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

11-
export type ThemeConfig = {
12-
algolia: {
13-
contextualSearch: boolean;
14-
externalUrlRegex?: string;
15-
appId: string;
16-
apiKey: string;
17-
indexName: string;
18-
searchParameters: {[key: string]: unknown};
19-
searchPagePath: string | false | null;
20-
replaceSearchResultPathname?: {
21-
from: string;
22-
to: string;
23-
};
24-
insights?: boolean;
12+
// DocSearch props that Docusaurus exposes directly through props forwarding
13+
type DocusaurusDocSearchProps = Pick<
14+
DocSearchProps,
15+
| 'appId'
16+
| 'apiKey'
17+
| 'indexName'
18+
| 'placeholder'
19+
| 'translations'
20+
| 'searchParameters'
21+
| 'insights'
22+
| 'initialQuery'
23+
>;
24+
25+
type ThemeConfigAlgolia = DocusaurusDocSearchProps & {
26+
// Docusaurus custom options, not coming from DocSearch
27+
contextualSearch: boolean;
28+
externalUrlRegex?: string;
29+
searchPagePath: string | false | null;
30+
replaceSearchResultPathname?: {
31+
from: string;
32+
to: string;
2533
};
2634
};
35+
36+
export type ThemeConfig = DocusaurusDocSearchProps & {
37+
algolia: ThemeConfigAlgolia;
38+
};
39+
2740
export type UserThemeConfig = DeepPartial<ThemeConfig>;
2841
}
2942

packages/docusaurus-theme-search-algolia/src/theme/SearchBar/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ function DocSearch({
242242
onMouseOver={importDocSearchModalIfNeeded}
243243
onClick={openModal}
244244
ref={searchButtonRef}
245-
translations={translations.button}
245+
translations={props.translations?.button ?? translations.button}
246246
/>
247247

248248
{isOpen &&
@@ -260,10 +260,10 @@ function DocSearch({
260260
{...(props.searchPagePath && {
261261
resultsFooterComponent,
262262
})}
263+
placeholder={translations.placeholder}
263264
{...props}
265+
translations={props.translations?.modal ?? translations.modal}
264266
searchParameters={searchParameters}
265-
placeholder={translations.placeholder}
266-
translations={translations.modal}
267267
/>,
268268
searchContainer.current,
269269
)}

0 commit comments

Comments
 (0)