Make sidebar a responsive off-canvas drawer on mobile
The fixed 260px sidebar overlapped page content on phones. Below 768px the app container now stacks vertically: a full-width hamburger top bar sits above the content, the sidebar slides off-canvas behind a tap/Escape-dismissable backdrop, and the main content uses full width. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
62d799a60d
commit
8e5eb387c5
5 files changed
+129
-1
No files matched your search
@@ -17,8 +17,44 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
|
||||
// 4. Initialize drag and drop mechanics for directories and assets
|
||||
initDragAndDrop();
|
||||
|
||||
// 5. Mobile sidebar drawer interactions
|
||||
initMobileSidebar();
|
||||
});
|
||||
|
||||
// Mobile off-canvas sidebar drawer
|
||||
function toggleSidebar() {
|
||||
const sidebar = document.getElementById("sidebar");
|
||||
if (!sidebar) return;
|
||||
sidebar.classList.contains("open") ? closeSidebar() : openSidebar();
|
||||
}
|
||||
|
||||
function openSidebar() {
|
||||
const sidebar = document.getElementById("sidebar");
|
||||
const backdrop = document.querySelector(".sidebar-backdrop");
|
||||
if (sidebar) sidebar.classList.add("open");
|
||||
if (backdrop) backdrop.classList.add("show");
|
||||
}
|
||||
|
||||
function closeSidebar() {
|
||||
const sidebar = document.getElementById("sidebar");
|
||||
const backdrop = document.querySelector(".sidebar-backdrop");
|
||||
if (sidebar) sidebar.classList.remove("open");
|
||||
if (backdrop) backdrop.classList.remove("show");
|
||||
}
|
||||
|
||||
function initMobileSidebar() {
|
||||
// Close the drawer after tapping a nav link so the destination is visible
|
||||
document.querySelectorAll(".sidebar .nav-link").forEach(link => {
|
||||
link.addEventListener("click", closeSidebar);
|
||||
});
|
||||
|
||||
// Close on Escape for keyboard/accessibility
|
||||
document.addEventListener("keydown", (e) => {
|
||||
if (e.key === "Escape") closeSidebar();
|
||||
});
|
||||
}
|
||||
|
||||
function setupToastListeners() {
|
||||
const observer = new MutationObserver((mutations) => {
|
||||
mutations.forEach((mutation) => {
|
||||
|
||||
Reference in new issue
Block a user