From bc58b16ddda458851d4ddb9b184cb18fbaf359c1 Mon Sep 17 00:00:00 2001 From: seriouselly Date: Fri, 12 Jun 2026 12:57:30 +0700 Subject: [PATCH] feat(layout): auto-collapse sidebar when clicking main content area - Import `useUiStore` into `main-layout.tsx` to access the global sidebar state. - Add an `onClick` event listener to the main content wrapper. - Automatically close the sidebar if it is expanded and the user clicks outside of it. - Enhance overall UX by providing a more intuitive, frictionless way to dismiss the navigation menu. --- .../web/src/components/layout/main-layout.tsx | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/apps/web/src/components/layout/main-layout.tsx b/apps/web/src/components/layout/main-layout.tsx index 6ec3a1e..5179f45 100644 --- a/apps/web/src/components/layout/main-layout.tsx +++ b/apps/web/src/components/layout/main-layout.tsx @@ -3,19 +3,29 @@ import { Footer } from "./footer"; import { Sidebar } from "./sidebar"; import { MobileNav } from "./mobile-nav"; import { Leaf, Menu } from "lucide-react"; +import { useUiStore } from "@/store/ui-store"; type Props = { children: ReactNode }; export function MainLayout({ children }: Props) { const [mobileMenuOpen, setMobileMenuOpen] = useState(false); + const isSidebarOpen = useUiStore((state) => state.isSidebarOpen); + const setIsSidebarOpen = useUiStore((state) => state.setIsSidebarOpen); + return (
{/* Sidebar Desktop */} {/* Main Content */} -
+
{ + if (isSidebarOpen) { + setIsSidebarOpen(false); + } + }} + > {/* Header Mobile */}
@@ -40,10 +50,12 @@ export function MainLayout({ children }: Props) {
{/* Mobile Navigation */} - setMobileMenuOpen(false)} - /> +
+ setMobileMenuOpen(false)} + /> +
{/* Page Content */}