Skip to content

Commit 55ca03a

Browse files
committed
Mobile fixes for docs site
1 parent 8f4b94e commit 55ca03a

File tree

4 files changed

+95
-11
lines changed

4 files changed

+95
-11
lines changed

site-src/assets/app.js

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,51 @@ const sidebar = document.getElementById("sidebar");
2121
const overlay = document.getElementById("sidebarOverlay");
2222
const menuBtn = document.getElementById("menuBtn");
2323

24-
function openSidebar() {
25-
sidebar?.classList.add("open");
26-
overlay?.classList.add("visible");
24+
function drawerOpen() {
25+
return Boolean(sidebar?.classList.contains("open"));
2726
}
28-
function closeSidebar() {
29-
sidebar?.classList.remove("open");
30-
overlay?.classList.remove("visible");
27+
28+
function setDrawerOpen(open) {
29+
if (!sidebar || !overlay) return;
30+
sidebar.classList.toggle("open", open);
31+
overlay.classList.toggle("visible", open);
32+
document.body.classList.toggle("nav-drawer-open", open);
33+
overlay.setAttribute("aria-hidden", open ? "false" : "true");
34+
if (menuBtn) {
35+
menuBtn.setAttribute("aria-expanded", open ? "true" : "false");
36+
menuBtn.setAttribute("aria-label", open ? "Close menu" : "Open menu");
37+
}
38+
}
39+
40+
if (menuBtn && sidebar) {
41+
menuBtn.setAttribute("aria-controls", "sidebar");
42+
menuBtn.setAttribute("aria-expanded", "false");
3143
}
3244

33-
menuBtn?.addEventListener("click", openSidebar);
34-
overlay?.addEventListener("click", closeSidebar);
45+
menuBtn?.addEventListener("click", () => {
46+
if (!sidebar || !overlay) return;
47+
setDrawerOpen(!drawerOpen());
48+
});
49+
50+
overlay?.addEventListener("click", () => setDrawerOpen(false));
3551

3652
sidebar?.querySelectorAll(".sidebar-link").forEach((link) => {
3753
link.addEventListener("click", () => {
38-
if (window.innerWidth < 900) closeSidebar();
54+
if (window.innerWidth < 900) setDrawerOpen(false);
3955
});
4056
});
4157

58+
document.addEventListener("keydown", (e) => {
59+
if (e.key === "Escape" && drawerOpen()) {
60+
setDrawerOpen(false);
61+
menuBtn?.focus();
62+
}
63+
});
64+
65+
window.addEventListener("resize", () => {
66+
if (window.innerWidth >= 900 && drawerOpen()) setDrawerOpen(false);
67+
});
68+
4269
function attachCopyButton(pre) {
4370
if (pre.parentElement?.classList.contains("code-block")) return;
4471

site-src/assets/style.css

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,21 @@ li strong { color: var(--text); }
219219
cursor: pointer;
220220
color: var(--text);
221221
flex-shrink: 0;
222+
-webkit-tap-highlight-color: transparent;
222223
}
223224
.menu-btn svg { display: block; }
224225

226+
body.nav-drawer-open {
227+
overflow: hidden;
228+
}
229+
225230
/* ===== LAYOUT ===== */
226231
.page-layout {
227232
display: grid;
228233
grid-template-columns: var(--sidebar-w) 1fr;
229234
min-height: 100vh;
230235
padding-top: var(--header-h);
231236
position: relative;
232-
z-index: 1;
233237
}
234238

235239
/* ===== SIDEBAR ===== */
@@ -496,9 +500,16 @@ tbody tr:hover td { background: var(--glass); }
496500
background: rgba(0,0,0,0.55);
497501
z-index: 150;
498502
backdrop-filter: blur(2px);
503+
-webkit-tap-highlight-color: transparent;
499504
}
500505
.sidebar-overlay.visible { display: block; }
501506

507+
@media (min-width: 901px) {
508+
.sidebar.sidebar--standalone {
509+
display: none;
510+
}
511+
}
512+
502513
/* ===== LANDING ===== */
503514
.landing { position: relative; z-index: 1; padding-top: var(--header-h); }
504515

@@ -817,15 +828,21 @@ tbody tr:hover td { background: var(--glass); }
817828
position: fixed;
818829
top: 0; left: 0;
819830
height: 100vh;
820-
width: var(--sidebar-w);
831+
width: min(var(--sidebar-w), 88vw);
832+
max-width: 100%;
821833
z-index: 160;
822834
transform: translateX(-100%);
823835
transition: transform 0.24s cubic-bezier(0.4,0,0.2,1);
824836
padding-top: calc(var(--header-h) + 0.75rem);
825837
border-right: 1px solid var(--border-md);
838+
-webkit-overflow-scrolling: touch;
826839
}
827840
.sidebar.open { transform: translateX(0); }
828841

842+
.sidebar.sidebar--standalone {
843+
display: block;
844+
}
845+
829846
.menu-btn { display: flex; }
830847
.content { padding: 1.75rem 1.25rem 3rem; }
831848

@@ -841,6 +858,23 @@ tbody tr:hover td { background: var(--glass); }
841858
.hero h1 { font-size: 1.7rem; }
842859
.hero-sub { font-size: 0.95rem; }
843860
.header-nav a:not(.header-badge) { display: none; }
861+
.site-header {
862+
padding: 0 0.75rem;
863+
gap: 0.5rem;
864+
}
865+
.header-nav {
866+
gap: 0.05rem;
867+
flex-shrink: 1;
868+
min-width: 0;
869+
}
870+
.header-nav .header-badge {
871+
padding: 0.24rem 0.5rem;
872+
font-size: 0.72rem;
873+
}
874+
.header-nav .theme-btn {
875+
padding: 0.28rem 0.45rem;
876+
font-size: 0.74rem;
877+
}
844878
}
845879

846880
/* ===== DOC PAGES (long-form readability) ===== */

site-src/templates/changelog.html.jinja2

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@
7777
</button>
7878
</header>
7979

80+
<aside class="sidebar sidebar--standalone" id="sidebar" aria-label="Site navigation">
81+
<div class="sidebar-group">
82+
<span class="sidebar-label">Navigate</span>
83+
<a class="sidebar-link" href="getting-started.html">Documentation</a>
84+
<a class="sidebar-link" href="api/index.html">API reference</a>
85+
<a class="sidebar-link active" href="changelog.html" aria-current="page">Changelog</a>
86+
<a class="sidebar-link sidebar-ext" href="https://pypi.org/project/yokedcache/" target="_blank" rel="noopener">PyPI</a>
87+
<a class="sidebar-link sidebar-ext" href="{{ github_repo }}" target="_blank" rel="noopener">GitHub</a>
88+
</div>
89+
</aside>
90+
8091
<div style="position:relative;z-index:1;padding-top:var(--header-h)">
8192
<div class="changelog-wrap">
8293
<h1 class="page-title">Changelog</h1>

site-src/templates/index.html.jinja2

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@
8080
</button>
8181
</header>
8282

83+
<aside class="sidebar sidebar--standalone" id="sidebar" aria-label="Site navigation">
84+
<div class="sidebar-group">
85+
<span class="sidebar-label">Navigate</span>
86+
<a class="sidebar-link" href="getting-started.html">Documentation</a>
87+
<a class="sidebar-link" href="api/index.html">API reference</a>
88+
<a class="sidebar-link" href="changelog.html">Changelog</a>
89+
<a class="sidebar-link sidebar-ext" href="https://pypi.org/project/yokedcache/" target="_blank" rel="noopener">PyPI</a>
90+
<a class="sidebar-link sidebar-ext" href="{{ github_repo }}" target="_blank" rel="noopener">GitHub</a>
91+
</div>
92+
</aside>
93+
8394
<div class="landing">
8495
<section class="hero">
8596
<div class="hero-eyebrow">Open source · MIT License</div>
@@ -192,6 +203,7 @@
192203
</footer>
193204
</div>
194205

206+
<div class="sidebar-overlay" id="sidebarOverlay" aria-hidden="true"></div>
195207
<script src="assets/app.js"></script>
196208
</body>
197209
</html>

0 commit comments

Comments
 (0)