mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-12 19:16:41 +00:00
fix logic for which sections are open
This commit is contained in:
parent
e60ec269ba
commit
71a0fa1064
1 changed files with 23 additions and 5 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { FC } from 'react';
|
import { FC, useEffect, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
Accordion,
|
Accordion,
|
||||||
AccordionButton,
|
AccordionButton,
|
||||||
|
|
@ -24,16 +24,33 @@ interface Props {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DocsLinks: FC<Props> = ({ navLinks, toggleMobileAccordion }) => {
|
export const DocsLinks: FC<Props> = ({ navLinks, toggleMobileAccordion }) => {
|
||||||
const { asPath, query: { slug } } = useRouter();
|
const [openSections, setOpenSections] = useState<{ [key: string]: boolean }>({});
|
||||||
|
const {
|
||||||
|
asPath,
|
||||||
|
query: { slug }
|
||||||
|
} = useRouter();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setOpenSections(
|
||||||
|
navLinks.reduce(
|
||||||
|
(acc, navLink) => ({
|
||||||
|
...acc,
|
||||||
|
[navLink.id]: checkNavLinks({ items: navLink.items, pathCheck: asPath })
|
||||||
|
}),
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}, [asPath]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
return (
|
return (
|
||||||
<Stack border='2px' borderColor='primary'>
|
<Stack border='2px' borderColor='primary'>
|
||||||
{navLinks.map(({ id, to, items }, idx) => {
|
{navLinks.map(({ id, to, items }, idx) => {
|
||||||
const split = to?.split('/');
|
const split = to?.split('/');
|
||||||
const isActive = slug && split && split[split.length - 1] === slug[slug.length - 1];
|
const isActive = slug && split && split[split.length - 1] === slug[slug.length - 1];
|
||||||
const isSectionActive = checkNavLinks({ to, items, pathCheck: asPath.split('#')[0] })
|
const handleToggle = () => {
|
||||||
|
setOpenSections(prev => ({ ...prev, [id]: !prev[id] }));
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<Accordion key={id} defaultIndex={isSectionActive ? 0 : -1} allowToggle mt='0 !important'>
|
<Accordion key={id} index={openSections[id] ? 0 : -1} allowToggle mt='0 !important'>
|
||||||
<AccordionItem border='none'>
|
<AccordionItem border='none'>
|
||||||
{({ isExpanded }) => (
|
{({ isExpanded }) => (
|
||||||
<>
|
<>
|
||||||
|
|
@ -45,6 +62,7 @@ export const DocsLinks: FC<Props> = ({ navLinks, toggleMobileAccordion }) => {
|
||||||
placeContent='flex-end'
|
placeContent='flex-end'
|
||||||
bg='button-bg'
|
bg='button-bg'
|
||||||
data-group
|
data-group
|
||||||
|
onClick={handleToggle}
|
||||||
>
|
>
|
||||||
<Stack
|
<Stack
|
||||||
p={4}
|
p={4}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue