From 9e5339c86b862392a0e5ee175bd1e985f089bb50 Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Mon, 21 Apr 2025 15:46:23 +0100 Subject: [PATCH] Close Navbar on outside click on mobile --- .../components/layouts/global/global-app-shell.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/apps/client/src/components/layouts/global/global-app-shell.tsx b/apps/client/src/components/layouts/global/global-app-shell.tsx index 585fb249..c8aff4cc 100644 --- a/apps/client/src/components/layouts/global/global-app-shell.tsx +++ b/apps/client/src/components/layouts/global/global-app-shell.tsx @@ -14,6 +14,8 @@ import { AppHeader } from "@/components/layouts/global/app-header.tsx"; import Aside from "@/components/layouts/global/aside.tsx"; import classes from "./app-shell.module.css"; import { useTrialEndAction } from "@/ee/hooks/use-trial-end-action.tsx"; +import { useClickOutside, useMergedRef } from "@mantine/hooks"; +import { useToggleSidebar } from "@/components/layouts/global/hooks/hooks/use-toggle-sidebar.ts"; export default function GlobalAppShell({ children, @@ -22,11 +24,19 @@ export default function GlobalAppShell({ }) { useTrialEndAction(); const [mobileOpened] = useAtom(mobileSidebarAtom); + const toggleMobile = useToggleSidebar(mobileSidebarAtom); const [desktopOpened] = useAtom(desktopSidebarAtom); const [{ isAsideOpen }] = useAtom(asideStateAtom); const [sidebarWidth, setSidebarWidth] = useAtom(sidebarWidthAtom); const [isResizing, setIsResizing] = useState(false); const sidebarRef = useRef(null); + const navbarOutsideRef = useClickOutside(() => { + if (mobileOpened) { + toggleMobile(); + } + }); + + const mergedRef = useMergedRef(sidebarRef, navbarOutsideRef); const startResizing = React.useCallback((mouseDownEvent) => { mouseDownEvent.preventDefault(); @@ -102,7 +112,7 @@ export default function GlobalAppShell({
{isSpaceRoute && }