From 63084e945fac4609cb450c7822c9bfa7771b11fb Mon Sep 17 00:00:00 2001 From: veselovnk Date: Thu, 27 Jun 2024 11:31:00 +0300 Subject: [PATCH] MSP-3523 fix menu collapse --- src/components/Layout/index.tsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/components/Layout/index.tsx b/src/components/Layout/index.tsx index 6656cd4..c856efa 100644 --- a/src/components/Layout/index.tsx +++ b/src/components/Layout/index.tsx @@ -32,7 +32,10 @@ import { routePaths } from '@routes/routePaths.ts' import { PermissionKeysType } from '@type/roles.type.ts' -import './layout.scss' + + +import './layout.scss'; + const { Content, Sider } = Layout @@ -138,17 +141,16 @@ const LayoutComponent = () => { useEffect(() => { const menuKey = location.pathname.split('/')[1] as MenuItemKeysType - + const selectedKey = selectedMenuKeys[0] || '' const menuItem = menuKeys[menuKey] - if (menuItem) { + if (menuItem && menuKey !== selectedKey) { setSelectedMenuKeys([menuItem.key]) - setOpenKeys(menuItem.parent) - } else { - setSelectedMenuKeys([]) - setOpenKeys([]) + if (selectedKey) { + setOpenKeys(menuItem.parent) + } } - }, [location]) + }, [location.pathname]) const handlerOnClickMenu: MenuProps['onClick'] = ({ key }): void => { switch (key) {