Skip to content

Commit 18343ae

Browse files
Kyle McLarenclaude
andcommitted
Unbold nested sidebar group labels and auto-expand current page group
- Fix CSS selector to properly target .large class in nested details - Auto-expand sidebar group when navigating to that page - Click group heading navigates to page top (not anchor) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 67349bf commit 18343ae

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/components/Head.astro

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,15 @@ const breadcrumbSchema = {
188188
<!-- Sidebar group navigation: click heading to expand and navigate to page -->
189189
<script>
190190
function initSidebarNavigation() {
191+
const currentPath = window.location.pathname;
192+
191193
// Find all nested sidebar groups within API Reference
192194
const sidebarGroups = document.querySelectorAll('nav[aria-label="Main"] details details');
193195

194196
sidebarGroups.forEach((details) => {
195197
const summary = details.querySelector(':scope > summary');
196198
if (!summary) return;
197199

198-
// Skip if already initialized
199-
if (summary.dataset.navInit) return;
200-
summary.dataset.navInit = 'true';
201-
202200
// Find the first link within this group to determine the page URL
203201
const firstLink = details.querySelector(':scope > ul a[href]');
204202
if (!firstLink) return;
@@ -208,6 +206,15 @@ const breadcrumbSchema = {
208206
const pageUrl = href.split('#')[0];
209207
if (!pageUrl) return;
210208

209+
// Auto-expand if current page matches this group's page
210+
if (currentPath === pageUrl || currentPath === pageUrl.replace(/\/$/, '')) {
211+
details.setAttribute('open', '');
212+
}
213+
214+
// Skip click handler setup if already initialized
215+
if (summary.dataset.navInit) return;
216+
summary.dataset.navInit = 'true';
217+
211218
// Add click handler to summary
212219
summary.addEventListener('click', (e) => {
213220
// Allow normal toggle behavior with modifier keys
@@ -217,8 +224,6 @@ const breadcrumbSchema = {
217224
if (!details.open) {
218225
e.preventDefault();
219226
e.stopPropagation();
220-
// Manually open the details element
221-
details.setAttribute('open', '');
222227
// Navigate to the page (without anchor hash)
223228
window.location.href = pageUrl;
224229
}

src/styles/custom.css

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,12 +1711,16 @@ h2.method-title {
17111711
Sidebar API Group Labels - Unbold nested group headings
17121712
============================================================================ */
17131713

1714-
/* Unbold sidebar group labels for API Reference nested groups */
1715-
.sidebar-content .top-level > li > details > ul details > summary span {
1714+
/* Target nested details (e.g., Sprites, Checkpoints inside API Reference) */
1715+
/* The .large class inside these should match regular link styling */
1716+
.sidebar details details summary .large {
17161717
font-weight: 400 !important;
1718+
font-size: var(--sl-text-sm) !important;
1719+
color: var(--sl-color-gray-2) !important;
17171720
}
17181721

1719-
/* Alternative broader selector for nested details summaries */
1720-
nav[aria-label="Main"] details details summary span {
1721-
font-weight: 400 !important;
1722+
@media (min-width: 50rem) {
1723+
.sidebar details details summary .large {
1724+
font-size: var(--sl-text-sm) !important;
1725+
}
17221726
}

0 commit comments

Comments
 (0)