fix(layout): correct sidebar toggle behavior and navigation logic

- Remove `onClick` toggle handler from `Sidebar` links to prevent unwanted state changes during navigation.
- Remove aggressive `onClick` auto-collapse from `MainLayout` content wrapper so the sidebar remains stable.
- Ensure sidebar state is exclusively managed by the dedicated toggle button, aligning with standard desktop UX.
This commit is contained in:
seriouselly
2026-06-14 22:25:46 +07:00
parent 5272968c6f
commit fe2734310a
2 changed files with 7 additions and 14 deletions
@@ -19,13 +19,7 @@ export function MainLayout({ children }: Props) {
<Sidebar /> <Sidebar />
{/* Main Content */} {/* Main Content */}
<div className="flex-1 flex flex-col w-full h-screen overflow-hidden" <div className="flex-1 flex flex-col w-full h-screen overflow-hidden">
onClick={() => {
if (isSidebarOpen) {
setIsSidebarOpen(false);
}
}}
>
{/* Header Mobile */} {/* Header Mobile */}
<div className="md:hidden flex items-center justify-between px-5 h-20 bg-[#306D29] text-white shrink-0 shadow-sm z-20"> <div className="md:hidden flex items-center justify-between px-5 h-20 bg-[#306D29] text-white shrink-0 shadow-sm z-20">
<div className="flex items-center gap-3 font-semibold"> <div className="flex items-center gap-3 font-semibold">
+6 -7
View File
@@ -3,14 +3,14 @@ import { Link, useLocation } from "react-router-dom";
import { import {
Leaf, Leaf,
LogOut, LogOut,
Menu, ChevronsLeft,
ChevronLeft,
LayoutDashboard, LayoutDashboard,
Scan, Scan,
Activity, Activity,
BookOpen, BookOpen,
UserCheck, UserCheck,
ChartBar, ChartBar,
ChevronsRight,
} from "lucide-react"; } from "lucide-react";
import { MobileNav } from "./mobile-nav"; import { MobileNav } from "./mobile-nav";
import { useAuthStore } from "@/store/auth-store"; import { useAuthStore } from "@/store/auth-store";
@@ -81,6 +81,7 @@ export function Sidebar() {
</div> </div>
</div> </div>
{/* Toggle Button */}
<button <button
onClick={() => setIsSidebarOpen(!isSidebarOpen)} onClick={() => setIsSidebarOpen(!isSidebarOpen)}
className={`rounded-xl transition-colors flex items-center justify-center shrink-0 ${ className={`rounded-xl transition-colors flex items-center justify-center shrink-0 ${
@@ -91,9 +92,9 @@ export function Sidebar() {
title={isSidebarOpen ? "Sembunyikan Menu" : "Buka Menu"} title={isSidebarOpen ? "Sembunyikan Menu" : "Buka Menu"}
> >
{isSidebarOpen ? ( {isSidebarOpen ? (
<ChevronLeft className="w-5 h-5" /> <ChevronsLeft className="w-7 h-7" />
) : ( ) : (
<Menu className="w-6 h-6" /> <ChevronsRight className="w-7 h-7" />
)} )}
</button> </button>
</div> </div>
@@ -103,7 +104,6 @@ export function Sidebar() {
className={`flex-1 overflow-y-auto py-6 flex flex-col gap-3 ${isSidebarOpen ? "px-5" : "px-0 items-center"}`} className={`flex-1 overflow-y-auto py-6 flex flex-col gap-3 ${isSidebarOpen ? "px-5" : "px-0 items-center"}`}
> >
{filteredNavItems.map((item) => { {filteredNavItems.map((item) => {
// Skip expert-only items for non-expert users
if (item.expertOnly && !isExpert) { if (item.expertOnly && !isExpert) {
return null; return null;
} }
@@ -116,7 +116,6 @@ export function Sidebar() {
key={item.path} key={item.path}
to={item.path} to={item.path}
title={item.label} title={item.label}
onClick={() => setIsSidebarOpen(!isSidebarOpen)}
className={`flex items-center rounded-full font-medium transition-all ${ className={`flex items-center rounded-full font-medium transition-all ${
isSidebarOpen isSidebarOpen
? "px-4 py-3 gap-3 text-[16px] w-full" ? "px-4 py-3 gap-3 text-[16px] w-full"
@@ -160,4 +159,4 @@ export function Sidebar() {
/> />
</aside> </aside>
); );
} }