🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(nav): close the mobile nav drawer when navigation starts (LFE-11067) (#15327)
Nikita Kabardine6ad9136ca3d
diff --git a/web/src/components/ui/sidebar.tsx b/web/src/components/ui/sidebar.tsxindex e09833eb79..3bbb60bd73 100644--- a/web/src/components/ui/sidebar.tsx+++ b/web/src/components/ui/sidebar.tsx@@ -1,6 +1,7 @@"use client";import * as React from "react";+import { useRouter } from "next/router";import { Slot } from "@radix-ui/react-slot";import { type VariantProps, cva } from "class-variance-authority";import { Menu, PanelLeft } from "lucide-react";@@ -67,6 +68,7 @@ const SidebarProvider = React.forwardRef<ref,) => {const isMobile = useIsMobile();+ const router = useRouter();const [openMobile, setOpenMobile] = React.useState(false);// Use local storage to persist sidebar state@@ -114,6 +116,18 @@ const SidebarProvider = React.forwardRef<return () => window.removeEventListener("keydown", handleKeyDown);}, [toggleSidebar]);+ // Close the mobile drawer as soon as a navigation starts. The drawer is a+ // full-screen overlay Sheet on mobile; without this it stays open on top of+ // the destination after tapping a nav link or switching project/org (the+ // Next.js router does shallow client transitions, so the component never+ // unmounts to reset `openMobile`). Subscribing to router events is a genuine+ // external-system effect. No-op on desktop, where `openMobile` is unused.+ React.useEffect(() => {+ const closeDrawer = () => setOpenMobile(false);+ router.events.on("routeChangeStart", closeDrawer);+ return () => router.events.off("routeChangeStart", closeDrawer);+ }, [router.events]);+// We add a state so that we can do data-state="expanded" or "collapsed".// This makes it easier to style the sidebar with Tailwind classes.const state = open ? "expanded" : "collapsed";