Skip to content
This repository has been archived by the owner on Jun 11, 2021. It is now read-only.

Commit

Permalink
feat(docsearch): forward props to autocomplete-core
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Apr 9, 2020
1 parent 73a7f0e commit 7cbcb12
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/docsearch-react/src/DocSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import {
createAutocomplete,
AutocompleteState,
PublicAutocompleteOptions,
} from '@francoischalifour/autocomplete-core';
import { getAlgoliaHits } from '@francoischalifour/autocomplete-preset-algolia';

Expand All @@ -17,7 +18,11 @@ import { SearchBox } from './SearchBox';
import { ScreenState } from './ScreenState';
import { Footer } from './Footer';

interface DocSearchProps {
interface DocSearchProps
extends Omit<
PublicAutocompleteOptions<InternalDocSearchHit>,
'onStateChange' | 'getSources'
> {
appId?: string;
apiKey: string;
indexName: string;
Expand All @@ -31,6 +36,7 @@ export function DocSearch({
indexName,
searchParameters,
onClose = noop,
...autocompleteProps
}: DocSearchProps) {
const [state, setState] = React.useState<
AutocompleteState<InternalDocSearchHit>
Expand Down Expand Up @@ -100,6 +106,7 @@ export function DocSearch({
initialState: {
query: initialQuery,
},
...autocompleteProps,
onStateChange({ state }) {
setState(state as any);
},
Expand Down
7 changes: 7 additions & 0 deletions packages/website/src/theme/SearchBar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import React, { useState, useEffect, useCallback } from 'react';
import { createPortal } from 'react-dom';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import { useHistory } from '@docusaurus/router';
import { SearchButton } from 'docsearch-react';

let DocSearch = null;
Expand All @@ -11,6 +12,7 @@ function SearchBar() {
const [isLoaded, setIsLoaded] = useState(false);
const [isShowing, setIsShowing] = useState(false);
const { siteConfig = {} } = useDocusaurusContext();
const history = useHistory();

const {
indexName,
Expand Down Expand Up @@ -90,6 +92,11 @@ function SearchBar() {
indexName={indexName}
searchParameters={searchParameters}
onClose={onClose}
navigator={{
navigate({ suggestionUrl }) {
history.push(suggestionUrl);
},
}}
/>,
document.body
)}
Expand Down

0 comments on commit 7cbcb12

Please sign in to comment.