Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/hooks/useKeyRecords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()];

Expand Down
35 changes: 33 additions & 2 deletions tests/SubMenu.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,31 @@ describe('SubMenu', () => {
expect(childText).toEqual('submenu');
});

it(`The submenu item with key '' must not persistently remain active`, () => {
const { container } = render(
<Menu
mode="horizontal"
items={[
{
label: '菜单一',
key: '1',
},
{
label: '菜单二',
key: '',
children: [
{
label: 'Navigation One1',
key: 'mail1',
},
],
},
]}
/>,
);
expect(container.querySelector('.rc-menu-submenu-active')).toBeFalsy();
});

describe('openSubMenuOnMouseEnter and closeSubMenuOnMouseLeave are true', () => {
it('toggles when mouse enter and leave', () => {
const { container } = render(
Expand Down Expand Up @@ -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 */