Skip to content

Commit

Permalink
[BLOG-42] fix(globalSearch): close mobile nav on search click
Browse files Browse the repository at this point in the history
  • Loading branch information
shaun-jacks committed May 31, 2020
1 parent cb18ad2 commit 6b60310
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/components/Nav/MobileNavMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default function MobileNavMenu({
},
}}
>
<Search />
<Search setMobileNavOpen={setOpen} />
</div>
</div>
);
Expand Down
23 changes: 13 additions & 10 deletions src/components/Search/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import React, { useState, useEffect, createRef, useMemo } from "react";
import {
InstantSearch,
Index,
Hits,
connectStateResults,
} from "react-instantsearch-dom";
import React, { useState, useMemo, useRef } from "react";
import { InstantSearch, Index, Hits } from "react-instantsearch-dom";
import algoliasearch from "algoliasearch/lite";
import {
HitsWrapper,
Expand All @@ -18,9 +13,17 @@ import CustomStateResults from "./CustomStateResults";
/** @jsx jsx */
import { Styled, jsx } from "theme-ui";

export default function Search() {
interface SearchProps {
setMobileNavOpen?: (val: boolean) => void;
}

export default function Search({
setMobileNavOpen = (val) => {},
}: SearchProps) {
const ref = useRef<HTMLDivElement>();
const [query, setQuery] = useState(``);
const [focus, setFocus] = useState(false);

const searchClient = useMemo(
() =>
algoliasearch(
Expand All @@ -30,7 +33,7 @@ export default function Search() {
[]
);
return (
<Styled>
<div onClick={() => setMobileNavOpen(false)}>
<InstantSearch
searchClient={searchClient}
indexName={"Posts"}
Expand Down Expand Up @@ -77,6 +80,6 @@ export default function Search() {
</div>
)}
</InstantSearch>
</Styled>
</div>
);
}

0 comments on commit 6b60310

Please sign in to comment.