From 63ddce899de05cbfb530e4b03d04a92feba67da9 Mon Sep 17 00:00:00 2001 From: zhwcreate <3331598351@qq.com> Date: Mon, 10 Jun 2024 14:05:49 +0800 Subject: [PATCH 1/5] fix: active wrong when submenus has key '' --- src/hooks/useKeyRecords.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/hooks/useKeyRecords.ts b/src/hooks/useKeyRecords.ts index db27d1ab..36811dd1 100644 --- a/src/hooks/useKeyRecords.ts +++ b/src/hooks/useKeyRecords.ts @@ -73,15 +73,18 @@ export default function useKeyRecords() { ); const isSubPathKey = useCallback( - (pathKeys: string[], eventKey: string) => - pathKeys.some(pathKey => { + (pathKeys: string[], eventKey: string) => { + if (pathKeys.every(key => key === undefined)) { + return false; + } + return pathKeys.some(pathKey => { const pathKeyList = getKeyPath(pathKey, true); return pathKeyList.includes(eventKey); - }), + }); + }, [getKeyPath], ); - const getKeys = () => { const keys = [...key2pathRef.current.keys()]; From 6cc83183ad9f248a9cb6d2985e8548cdac378984 Mon Sep 17 00:00:00 2001 From: zhwcreate <3331598351@qq.com> Date: Mon, 10 Jun 2024 16:45:42 +0800 Subject: [PATCH 2/5] feat:optimise code --- src/hooks/useKeyRecords.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/hooks/useKeyRecords.ts b/src/hooks/useKeyRecords.ts index 36811dd1..c4c884e9 100644 --- a/src/hooks/useKeyRecords.ts +++ b/src/hooks/useKeyRecords.ts @@ -73,16 +73,13 @@ export default function useKeyRecords() { ); const isSubPathKey = useCallback( - (pathKeys: string[], eventKey: string) => { - if (pathKeys.every(key => key === undefined)) { - return false; - } - return pathKeys.some(pathKey => { - const pathKeyList = getKeyPath(pathKey, true); - - return pathKeyList.includes(eventKey); - }); - }, + (pathKeys: string[], eventKey: string) => + pathKeys + .filter(item => item !== undefined) + .some(pathKey => { + const pathKeyList = getKeyPath(pathKey, true); + return pathKeyList.includes(eventKey); + }), [getKeyPath], ); const getKeys = () => { From b7ae9184db2978d4d77ea7e7fcc300188aef1ff2 Mon Sep 17 00:00:00 2001 From: zhwcreate <3331598351@qq.com> Date: Mon, 10 Jun 2024 17:07:34 +0800 Subject: [PATCH 3/5] feat: add test --- tests/SubMenu.spec.tsx | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/tests/SubMenu.spec.tsx b/tests/SubMenu.spec.tsx index f33f2426..5ec7fead 100644 --- a/tests/SubMenu.spec.tsx +++ b/tests/SubMenu.spec.tsx @@ -149,6 +149,30 @@ describe('SubMenu', () => { ).textContent; expect(childText).toEqual('submenu'); }); + it("The submenu item with key '' must not persistently remain active.", () => { + const { container } = render( +
, + ); + expect(container.querySelector('.rc-menu-submenu-active')).toBeFalsy() + }); describe('openSubMenuOnMouseEnter and closeSubMenuOnMouseLeave are true', () => { it('toggles when mouse enter and leave', () => { @@ -496,8 +520,14 @@ describe('SubMenu', () => { fireEvent.mouseEnter(container.querySelector('.rc-menu-submenu-title')); runAllTimer(); - expect((container.querySelector('.rc-menu-submenu-popup') as HTMLElement).style.zIndex).toEqual('100'); - expect((container.querySelector('.rc-menu-submenu-popup') as HTMLElement).style.width).toEqual('150px'); + expect( + (container.querySelector('.rc-menu-submenu-popup') as HTMLElement).style + .zIndex, + ).toEqual('100'); + expect( + (container.querySelector('.rc-menu-submenu-popup') as HTMLElement).style + .width, + ).toEqual('150px'); }); }); /* eslint-enable */ From ec0d1eb6a2c8b043a9b0257e9cc21d64cbea314a Mon Sep 17 00:00:00 2001 From: zhwcreate <3331598351@qq.com> Date: Thu, 20 Jun 2024 13:42:49 +0800 Subject: [PATCH 4/5] fix:grammar --- tests/SubMenu.spec.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/SubMenu.spec.tsx b/tests/SubMenu.spec.tsx index 5ec7fead..4553e10d 100644 --- a/tests/SubMenu.spec.tsx +++ b/tests/SubMenu.spec.tsx @@ -149,7 +149,7 @@ describe('SubMenu', () => { ).textContent; expect(childText).toEqual('submenu'); }); - it("The submenu item with key '' must not persistently remain active.", () => { + it(`The submenu item with key '' must not persistently remain active`, () => { const { container } = render(