Skip to content

Commit 234ec92

Browse files
Merge branch 'next' into changeset-release/next
2 parents 9437923 + 70f2ff6 commit 234ec92

File tree

1 file changed

+52
-7
lines changed

1 file changed

+52
-7
lines changed

Diff for: www/src/components/navigation/tableOfContents.astro

+52-7
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,58 @@ headings = [{ depth: 2, slug: "overview", text: title }, ...headings].filter(
5656
).at(-1);
5757
// this occurs when the id = "toc-heading"
5858
if (!tocItem) return;
59-
const func = entry.isIntersecting ? "add" : "remove";
60-
tocItem.classList[func](
61-
"font-medium",
62-
"text-t3-purple-700",
63-
"dark:text-t3-purple-100",
64-
);
65-
tocItem.parentElement.classList[func]("border-t3-purple-300/100");
59+
60+
if (entry.isIntersecting) {
61+
// get current all active elements
62+
const currentActiveElements = Array.from(
63+
document.querySelectorAll(
64+
`[data-current-active-tab-content-item="true"]`,
65+
),
66+
);
67+
68+
// get current all parent active elements
69+
const currentActiveParentElements = Array.from(
70+
document.querySelectorAll(
71+
`[data-current-active-parent-tab-content-item="true"]`,
72+
),
73+
);
74+
75+
// if has active elements
76+
if (currentActiveElements.length) {
77+
// loop through all elements and remove class and attr
78+
for (const el of currentActiveElements) {
79+
el.classList.remove(
80+
"font-medium",
81+
"text-t3-purple-700",
82+
"dark:text-t3-purple-100",
83+
);
84+
el.removeAttribute("data-current-active-tab-content-item");
85+
}
86+
}
87+
// if has active parent elements
88+
if (currentActiveParentElements.length) {
89+
// loop through all parent elements and remove class and attr
90+
for (const parentEl of currentActiveParentElements) {
91+
parentEl.classList.remove("border-t3-purple-300/100");
92+
parentEl.removeAttribute(
93+
"data-current-active-parent-tab-content-item",
94+
);
95+
}
96+
}
97+
98+
tocItem.classList.add(
99+
"font-medium",
100+
"text-t3-purple-700",
101+
"dark:text-t3-purple-100",
102+
);
103+
tocItem.parentElement.classList.add("border-t3-purple-300/100");
104+
// set data attr to active element also will helpful when need to remove active state
105+
tocItem.setAttribute("data-current-active-tab-content-item", true);
106+
tocItem.parentElement.setAttribute(
107+
"data-current-active-parent-tab-content-item",
108+
true,
109+
);
110+
}
66111
});
67112
},
68113
{

0 commit comments

Comments
 (0)