diff --git a/components/CaseTOC.js b/components/CaseTOC.js index a7d90fd5e818..0e7e5ac8f8d6 100644 --- a/components/CaseTOC.js +++ b/components/CaseTOC.js @@ -4,6 +4,10 @@ import { twMerge } from "tailwind-merge"; import ArrowRight from "./icons/ArrowRight"; import { useHeadingsObserver } from "./helpers/useHeadingsObserver"; +const checkIfActive = (item, currSelected) => { + return item.slug === currSelected || item.children?.some((child) => checkIfActive(child, currSelected)); +} + const convertContentToTocItems = (content, level = 1) => { const tocItems = []; @@ -34,13 +38,14 @@ function TOCItem({ item, index, currSelected, closeMenu }) { closeMenu(); setOpen(false); }; + const active = useMemo(() => checkIfActive(item, currSelected), [item, currSelected]); return ( <>