From 35c0436f4f0e383e5fede6d8b8eaf8c825d7da04 Mon Sep 17 00:00:00 2001 From: Abhimanyu Rajeesh <63541653+abhimanyurajeesh@users.noreply.github.com> Date: Sun, 5 Jan 2025 18:19:28 +0530 Subject: [PATCH] Auto-Hide Sidebar on mobile (#9758) --- src/components/ui/sidebar/nav-main.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/components/ui/sidebar/nav-main.tsx b/src/components/ui/sidebar/nav-main.tsx index f50590ab35f..f69eed4e175 100644 --- a/src/components/ui/sidebar/nav-main.tsx +++ b/src/components/ui/sidebar/nav-main.tsx @@ -9,6 +9,7 @@ import { SidebarMenu, SidebarMenuButton, SidebarMenuItem, + useSidebar, } from "@/components/ui/sidebar"; export function NavMain({ @@ -20,6 +21,8 @@ export function NavMain({ icon?: string; }[]; }) { + const { isMobile, setOpenMobile } = useSidebar(); + return ( @@ -31,6 +34,11 @@ export function NavMain({ className={ "text-gray-600 transition font-normal hover:bg-gray-200 hover:text-green-700" } + onClick={() => { + if (isMobile) { + setOpenMobile(false); + } + }} >