From add93b2e3ebad3c31c09a4a84405714c03b0c63d Mon Sep 17 00:00:00 2001 From: sup39 Date: Sun, 6 Nov 2022 16:59:26 +0900 Subject: [PATCH] nav auto open --- components/Nav.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/Nav.tsx b/components/Nav.tsx index 824d30c..de5c480 100644 --- a/components/Nav.tsx +++ b/components/Nav.tsx @@ -13,9 +13,11 @@ export type NavEntryInfo = { export function NavEntry({ entry: {name, link, children}, dir, here, children: childrenJSX, }: {entry: NavEntryInfo, dir: string, here: string, children?: Body}) { - const [toggle, setToggle] = useState(false); const href = dir+link; const isHere = href.replace(/\/$/, '')===here; // remove trailing slash + const isRHere = isHere || here.startsWith(href); // here or is children + + const [toggle, setToggle] = useState(isRHere); const entryCls = 'nav-entry'+(isHere ? ' nav-here' : ''); return children?.length ?
<>