From 1b5195908c23208db2a056f8a0d7b8b4132c3dce Mon Sep 17 00:00:00 2001 From: Corwin Smith Date: Tue, 6 Dec 2022 16:19:55 -0700 Subject: [PATCH] close mobile docs dropdown when page is selected --- src/components/UI/docs/DocsLinks.tsx | 7 ++++--- src/components/UI/docs/DocsNav.tsx | 16 ++++++++++++---- src/components/UI/docs/LinksList.tsx | 9 +++++---- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/components/UI/docs/DocsLinks.tsx b/src/components/UI/docs/DocsLinks.tsx index ab77e803ae..1eb9d48bf3 100644 --- a/src/components/UI/docs/DocsLinks.tsx +++ b/src/components/UI/docs/DocsLinks.tsx @@ -19,9 +19,10 @@ import { NavLink } from '../../../types'; interface Props { navLinks: NavLink[]; + updateMobileAccordionState: () => void; } -export const DocsLinks: FC = ({ navLinks }) => { +export const DocsLinks: FC = ({ navLinks, updateMobileAccordionState }) => { const router = useRouter(); const { slug } = router.query; return ( @@ -52,7 +53,7 @@ export const DocsLinks: FC = ({ navLinks }) => { _groupHover={{ background: 'primary', color: 'bg', textDecoration: 'none' }} > {to ? ( - + = ({ navLinks }) => { {items && ( - + )} diff --git a/src/components/UI/docs/DocsNav.tsx b/src/components/UI/docs/DocsNav.tsx index 3dcb661d4e..e086db3748 100644 --- a/src/components/UI/docs/DocsNav.tsx +++ b/src/components/UI/docs/DocsNav.tsx @@ -1,4 +1,4 @@ -import { FC } from 'react'; +import { FC, useState } from 'react'; import { Accordion, AccordionButton, @@ -17,14 +17,22 @@ interface Props { } export const DocsNav: FC = ({ navLinks }) => { + const OPEN = 0; + const CLOSED = -1; + const [mobileAccordionState, setMobileAccordionState] = useState(CLOSED) + + const updateMobileAccordionState = () => { + setMobileAccordionState(mobileAccordionState === OPEN ? CLOSED : OPEN) + } + return ( - + - + = ({ navLinks }) => { - + diff --git a/src/components/UI/docs/LinksList.tsx b/src/components/UI/docs/LinksList.tsx index 6c9d838e1d..ed2674204b 100644 --- a/src/components/UI/docs/LinksList.tsx +++ b/src/components/UI/docs/LinksList.tsx @@ -7,9 +7,10 @@ import { NavLink } from '../../../types'; interface LinksListProps { links: NavLink[]; + updateMobileAccordionState: () => void; } -export const LinksList: FC = ({ links }) => { +export const LinksList: FC = ({ links, updateMobileAccordionState }) => { const router = useRouter(); const { slug } = router.query; return ( @@ -19,7 +20,7 @@ export const LinksList: FC = ({ links }) => { const isActive = slug && split && split[split.length - 1] === slug[slug.length - 1]; return to ? ( - + = ({ links }) => { - {items && } + {items && } ) : ( {id} - {items && } + {items && } ); })}