diff --git a/src/hooks/useKeyRecords.ts b/src/hooks/useKeyRecords.ts index db27d1ab..c4c884e9 100644 --- a/src/hooks/useKeyRecords.ts +++ b/src/hooks/useKeyRecords.ts @@ -74,14 +74,14 @@ export default function useKeyRecords() { const isSubPathKey = useCallback( (pathKeys: string[], eventKey: string) => - pathKeys.some(pathKey => { - const pathKeyList = getKeyPath(pathKey, true); - - return pathKeyList.includes(eventKey); - }), + pathKeys + .filter(item => item !== undefined) + .some(pathKey => { + const pathKeyList = getKeyPath(pathKey, true); + return pathKeyList.includes(eventKey); + }), [getKeyPath], ); - const getKeys = () => { const keys = [...key2pathRef.current.keys()]; diff --git a/tests/SubMenu.spec.tsx b/tests/SubMenu.spec.tsx index f33f2426..f77e6d76 100644 --- a/tests/SubMenu.spec.tsx +++ b/tests/SubMenu.spec.tsx @@ -150,6 +150,31 @@ describe('SubMenu', () => { 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', () => { const { container } = render( @@ -496,8 +521,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 */