From 9a776be13c6bd61a590146e674ea86b3234dca09 Mon Sep 17 00:00:00 2001 From: hamed <15238-genius.ha@users.noreply.drupalcode.org> Date: Thu, 23 Jul 2026 15:03:47 +0330 Subject: [PATCH] =?UTF-8?q?feat:=20ensure=20=D9=86=D9=88=D8=A8=D8=AA?= =?UTF-8?q?=E2=80=8C=D9=87=D8=A7=20menu=20remains=20always=20expanded=20in?= =?UTF-8?q?=20the=20sidebar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/admin/components/layout/Sidebar.test.tsx | 10 +++++----- assets/admin/components/layout/Sidebar.tsx | 9 +++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/assets/admin/components/layout/Sidebar.test.tsx b/assets/admin/components/layout/Sidebar.test.tsx index 44b289ff..d3ffb640 100644 --- a/assets/admin/components/layout/Sidebar.test.tsx +++ b/assets/admin/components/layout/Sidebar.test.tsx @@ -20,19 +20,19 @@ describe("Sidebar — expandable نوبت‌ها menu", () => { } as any); }); - it("renders نوبت‌ها as a collapsible parent and reveals sub-items on click", () => { + it("keeps نوبت‌ها always expanded regardless of route and click", () => { renderWithProviders(, { route: "/admin/dashboard" }); // منوی والد به شکل دکمه const parent = screen.getByRole("button", { name: /نوبت‌ها/ }); expect(parent).toBeInTheDocument(); - // در ابتدا (مسیر داشبورد) بسته است → زیرمنوها نیستند - expect(screen.queryByText("نوبت ها")).toBeNull(); + // حتی خارج از مسیر نوبت‌ها، زیرمنوها همیشه دیده می‌شوند + expect(screen.getByText("نوبت ها")).toBeInTheDocument(); + expect(screen.getByText("افزودن نوبت")).toBeInTheDocument(); + // کلیک روی والد آن را جمع نمی‌کند fireEvent.click(parent); - - // پس از باز شدن، دو زیرمنو دیده می‌شوند expect(screen.getByText("نوبت ها")).toBeInTheDocument(); expect(screen.getByText("افزودن نوبت")).toBeInTheDocument(); }); diff --git a/assets/admin/components/layout/Sidebar.tsx b/assets/admin/components/layout/Sidebar.tsx index e4756af0..2a164801 100644 --- a/assets/admin/components/layout/Sidebar.tsx +++ b/assets/admin/components/layout/Sidebar.tsx @@ -509,7 +509,12 @@ function NavItem({ const { icon: Icon, label, to, children } = item; const location = useLocation(); const childActive = !!children?.some((c) => location.pathname === c.to); - const [open, setOpen] = useState(childActive); + // منوی «نوبت‌ها» همیشه باز می‌ماند و جمع نمی‌شود. + const alwaysOpen = !!children?.some((c) => + c.to.startsWith("/admin/appointments"), + ); + const [openState, setOpen] = useState(childActive); + const open = alwaysOpen || openState; // منوی ساده — رفتار قبلی بدون تغییر. if (!children || children.length === 0) { @@ -553,7 +558,7 @@ function NavItem({ className={`nav-item${childActive ? " active" : ""}`} aria-expanded={open} title={!sidebarOpen ? label : undefined} - onClick={() => setOpen((o) => !o)} + onClick={() => !alwaysOpen && setOpen((o) => !o)} style={{ width: "100%", background: "none",