Skip to content

Commit 4f5c282

Browse files
committed
fix: add working close button and backdrop for mobile sideba
- Add close (X) button and backdrop overlay markup to #mainSidebar - Style new elements, scoped to mobile via media query - Wire close button, backdrop click, and Escape key to remove body.sidebar-active, which is the class actually controlling sidebar visibility (previous mobileSidebarToggle JS referenced a button that didn't exist in the markup, so the sidebar had no way to be dismissed once opened)
1 parent bf108db commit 4f5c282

3 files changed

Lines changed: 67 additions & 23 deletions

File tree

web-app/css/styles.css

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6394,3 +6394,41 @@ body.sidebar-collapsed .projects-section {
63946394
padding-right: 0 !important;
63956395
}
63966396
}
6397+
6398+
.sidebar-mobile-close {
6399+
display: none;
6400+
position: absolute;
6401+
top: 16px;
6402+
right: 16px;
6403+
width: 36px;
6404+
height: 36px;
6405+
border: none;
6406+
border-radius: 50%;
6407+
background: var(--bg-glass);
6408+
color: var(--text-primary);
6409+
font-size: 16px;
6410+
align-items: center;
6411+
justify-content: center;
6412+
cursor: pointer;
6413+
z-index: 1001;
6414+
}
6415+
.sidebar-backdrop {
6416+
display: none;
6417+
position: fixed;
6418+
inset: 0;
6419+
background: rgba(0, 0, 0, 0.5);
6420+
z-index: 999;
6421+
opacity: 0;
6422+
transition: opacity 0.3s ease;
6423+
pointer-events: none;
6424+
}
6425+
@media (max-width: 768px) {
6426+
.sidebar-mobile-close {
6427+
display: flex;
6428+
}
6429+
body.sidebar-active .sidebar-backdrop {
6430+
display: block;
6431+
opacity: 1;
6432+
pointer-events: auto;
6433+
}
6434+
}

web-app/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@
9595
</nav>
9696

9797
<aside class="sidebar-dock" id="mainSidebar">
98+
<button
99+
class="sidebar-mobile-close"
100+
id="sidebarMobileClose"
101+
aria-label="Close sidebar"
102+
type="button"
103+
>
104+
<i class="fas fa-times" aria-hidden="true"></i>
105+
</button>
98106
<div class="sidebar-search">
99107
<div class="search-box" style="position: relative">
100108
<i class="fas fa-search" aria-hidden="true"></i>
@@ -261,6 +269,7 @@
261269
</div>
262270
</div>
263271
</aside>
272+
<div class="sidebar-backdrop" id="sidebarBackdrop"></div>
264273

265274
<main id="main-content" tabindex="-1">
266275
<!-- Hero Section -->

web-app/js/main.js

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -350,32 +350,29 @@ document.addEventListener("DOMContentLoaded", function () {
350350
});
351351
}
352352

353-
/* ── Mobile Sidebar Toggle ──────────────────────────────── */
354-
var mobileSidebarToggle = document.getElementById("mobileSidebarToggle");
353+
/* ── Mobile Sidebar Close ──────────────────────────────── */
355354
var mainSidebar = document.getElementById("mainSidebar");
356-
if (mobileSidebarToggle && mainSidebar) {
357-
mobileSidebarToggle.addEventListener("click", function () {
358-
var active = mainSidebar.classList.toggle("open");
359-
mobileSidebarToggle.setAttribute("aria-expanded", active);
360-
var icon = mobileSidebarToggle.querySelector("i");
361-
if (icon) icon.className = active ? "fas fa-times" : "fas fa-bars";
362-
});
355+
var sidebarMobileClose = document.getElementById("sidebarMobileClose");
356+
var sidebarBackdrop = document.getElementById("sidebarBackdrop");
363357

364-
document.addEventListener("click", function (e) {
365-
if (
366-
mainSidebar &&
367-
mobileSidebarToggle &&
368-
!mainSidebar.contains(e.target) &&
369-
e.target !== mobileSidebarToggle &&
370-
mainSidebar.classList.contains("open")
371-
) {
372-
mainSidebar.classList.remove("open");
373-
mobileSidebarToggle.setAttribute("aria-expanded", "false");
374-
var icon = mobileSidebarToggle.querySelector("i");
375-
if (icon) icon.className = "fas fa-bars";
376-
}
377-
});
358+
function closeMobileSidebar() {
359+
document.body.classList.remove("sidebar-active");
360+
}
361+
362+
if (sidebarMobileClose) {
363+
sidebarMobileClose.addEventListener("click", closeMobileSidebar);
378364
}
365+
if (sidebarBackdrop) {
366+
sidebarBackdrop.addEventListener("click", closeMobileSidebar);
367+
}
368+
document.addEventListener("keydown", function (e) {
369+
if (
370+
e.key === "Escape" &&
371+
document.body.classList.contains("sidebar-active")
372+
) {
373+
closeMobileSidebar();
374+
}
375+
});
379376

380377
/* ── Desktop Sidebar Toggle ──────────────────────────────── */
381378
var desktopSidebarToggle = document.getElementById("sidebarCollapseBtn");

0 commit comments

Comments
 (0)