Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit12c1fca

Browse files
d3georged3george
d3george
authored and
d3george
committed
refactor: nav refactor
1 parent44fe6c3 commit12c1fca

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

‎src/layouts/dashboard/nav/nav-vertical.tsx‎

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import{Menu,MenuProps}from'antd';
22
importColorfrom'color';
3-
import{useMemo,useState}from'react';
3+
import{useEffect,useMemo,useState}from'react';
44
import{useMatches,useNavigate}from'react-router-dom';
55

66
importScrollbarfrom'@/components/scrollbar';
@@ -37,27 +37,32 @@ export default function NavVertical(props: Props) {
3737
constpermissionRoutes=usePermissionRoutes();
3838
constflattenedRoutes=useFlattenedRoutes();
3939

40-
const[collapsed,setCollapsed]=useState(themeLayout===ThemeLayout.Mini);
40+
constcollapsed=useMemo(()=>themeLayout===ThemeLayout.Mini,[themeLayout]);
41+
4142
constmenuList=useMemo(()=>{
4243
constmenuRoutes=menuFilter(permissionRoutes);
4344
returnrouteToMenuFn(menuRoutes);
4445
},[routeToMenuFn,permissionRoutes]);
4546

4647
constselectedKeys=useMemo(()=>[pathname],[pathname]);
47-
constopenKeys=useMemo(()=>{
48-
constkeys=matches
49-
.filter((match)=>match.pathname!=='/')
50-
.filter((match)=>match.pathname!==pathname)
51-
.map((match)=>match.pathname);
52-
returnkeys;
53-
},[matches,pathname]);
48+
49+
const[openKeys,setOpenKeys]=useState<string[]>([]);
50+
51+
useEffect(()=>{
52+
if(!collapsed){
53+
constkeys=matches
54+
.filter((match)=>match.pathname!=='/')
55+
.filter((match)=>match.pathname!==pathname)
56+
.map((match)=>match.pathname);
57+
setOpenKeys(keys);
58+
}
59+
},[matches,pathname,collapsed]);
5460

5561
consthandleToggleCollapsed=()=>{
5662
setSettings({
5763
...settings,
5864
themeLayout:collapsed ?ThemeLayout.Vertical :ThemeLayout.Mini,
5965
});
60-
setCollapsed(!collapsed);
6166
};
6267

6368
constonClick:MenuProps['onClick']=({ key, keyPath})=>{
@@ -75,6 +80,12 @@ export default function NavVertical(props: Props) {
7580
props?.closeSideBarDrawer?.();
7681
};
7782

83+
consthandleOpenChange:MenuProps['onOpenChange']=(keys)=>{
84+
if(!collapsed){
85+
setOpenKeys(keys);
86+
}
87+
};
88+
7889
return(
7990
<div
8091
style={{
@@ -94,6 +105,7 @@ export default function NavVertical(props: Props) {
94105
style={{backgroundColor:colorBgElevated}}
95106
className="h-full !border-none"
96107
onClick={onClick}
108+
onOpenChange={handleOpenChange}
97109
/>
98110
</Scrollbar>
99111
</div>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp