Skip to content

Commit d00a3f8

Browse files
committed
fix(docs): standardize missing accessibility and UX features
Add prefers-reduced-motion CSS media queries, Firefox scrollbar support, window.__docsSlug for route-based deep links, scrollspy nav auto-scroll, and mobile menu close on nav click to match standardized pattern
1 parent 20c12dd commit d00a3f8

2 files changed

Lines changed: 74 additions & 13 deletions

File tree

docs/src/pages/docs/[...slug].astro

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ const docsBase = Astro.site
124124
</div>
125125
</div>
126126

127+
{requestedSlug && <script is:inline define:vars={{ slug: requestedSlug, isRoot: isRoot }}>window.__docsSlug = slug; window.__isRoot = isRoot;</script>}
128+
127129
<script is:inline define:vars={{ isRoot, docsBase }}>
128130
document.addEventListener('DOMContentLoaded', function () {
129131
const sections = document.querySelectorAll('section.doc-section');
@@ -132,6 +134,7 @@ const docsBase = Astro.site
132134
const sidebar = document.getElementById('sidebar');
133135
const overlay = document.getElementById('overlay');
134136
const searchBox = document.getElementById('searchBox');
137+
const isRoot = window.__isRoot !== false;
135138
const prefersReducedMotion = !window.matchMedia('(prefers-reduced-motion: no-preference)').matches;
136139

137140
/* Mobile menu toggle */
@@ -147,37 +150,52 @@ const docsBase = Astro.site
147150
menuToggle.setAttribute('aria-expanded', String(isOpen));
148151
});
149152
overlay.addEventListener('click', closeMenu);
150-
navItems.forEach(function (item) {
151-
item.addEventListener('click', closeMenu);
152-
});
153153
}
154154

155-
/* Auto-scroll to hash section (root only) */
156-
if (isRoot && window.location.hash) {
157-
const targetId = window.location.hash.slice(1);
158-
const target = document.getElementById(targetId);
159-
if (target) {
160-
setTimeout(function () {
161-
target.scrollIntoView({ behavior: prefersReducedMotion ? 'auto' : 'smooth' });
162-
}, 100);
155+
/* Auto-scroll to section (root only) */
156+
if (isRoot) {
157+
const targetSlug = window.__docsSlug;
158+
const hash = window.location.hash;
159+
const sectionId = targetSlug || (hash && hash.length > 1 ? hash.slice(1) : null);
160+
if (sectionId) {
161+
const target = document.getElementById(sectionId);
162+
if (target) {
163+
setTimeout(function () {
164+
target.scrollIntoView({ behavior: prefersReducedMotion ? 'auto' : 'smooth' });
165+
}, 100);
166+
}
163167
}
164168
}
165169

166-
/* Scrollspy (root + multi-section only) */
170+
/* Scrollspy + nav click (root + multi-section only) */
167171
if (isRoot && sections.length > 1) {
168172
const observer = new IntersectionObserver(
169173
function (entries) {
170174
entries.forEach(function (entry) {
171175
if (entry.isIntersecting) {
172176
navItems.forEach(function (item) {
173-
item.classList.toggle('active', item.getAttribute('data-nav-id') === entry.target.id);
177+
var isActive = item.getAttribute('data-nav-id') === entry.target.id;
178+
item.classList.toggle('active', isActive);
179+
if (isActive) {
180+
item.scrollIntoView({ behavior: prefersReducedMotion ? 'auto' : 'smooth', block: 'nearest' });
181+
}
174182
});
175183
}
176184
});
177185
},
178186
{ root: null, rootMargin: '-80px 0px -60% 0px', threshold: 0 }
179187
);
180188
sections.forEach(function (section) { observer.observe(section); });
189+
190+
navItems.forEach(function (item) {
191+
item.addEventListener('click', function () {
192+
if (window.innerWidth <= 768 && menuToggle && sidebar && overlay) {
193+
sidebar.classList.remove('open');
194+
overlay.classList.remove('open');
195+
menuToggle.setAttribute('aria-expanded', 'false');
196+
}
197+
});
198+
});
181199
}
182200

183201
/* Search filter (root only) */

docs/src/styles/docs.css

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,49 @@
353353
z-index: 95;
354354
}
355355

356+
/* ── Scroll behavior / reduced motion ──────────────────────────────── */
357+
@media (prefers-reduced-motion: no-preference) {
358+
html { scroll-behavior: smooth; }
359+
}
360+
361+
@media (prefers-reduced-motion: reduce) {
362+
*, *::before, *::after {
363+
animation-duration: 0s !important;
364+
animation-iteration-count: 1 !important;
365+
transition-duration: 0s !important;
366+
}
367+
}
368+
369+
/* ── Custom scrollbar ─────────────────────────────────────────────── */
370+
html {
371+
scrollbar-color: var(--rust-orange) var(--bg-deep);
372+
scrollbar-width: thin;
373+
}
374+
375+
::-webkit-scrollbar {
376+
width: 6px;
377+
height: 6px;
378+
}
379+
380+
::-webkit-scrollbar-track {
381+
background: var(--bg-deep);
382+
border-left: 1px solid rgba(45, 26, 0, 0.5);
383+
}
384+
385+
::-webkit-scrollbar-thumb {
386+
background: var(--rust-orange);
387+
border-radius: 3px;
388+
transition: background 0.2s;
389+
}
390+
391+
::-webkit-scrollbar-thumb:hover {
392+
background: #DEA584;
393+
}
394+
395+
::-webkit-scrollbar-corner {
396+
background: var(--bg-deep);
397+
}
398+
356399
/* ── Scrollbar (docs sidebar) ──────────────────────────────────────── */
357400
.docs-layout .sidebar::-webkit-scrollbar {
358401
width: 4px;

0 commit comments

Comments
 (0)