Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: active wrong when submenus has key '' #721

Merged
merged 5 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
34 changes: 32 additions & 2 deletions tests/SubMenu.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,30 @@ describe('SubMenu', () => {
).textContent;
expect(childText).toEqual('submenu');
});
it("The submenu item with key '' must not persistently remain active.", () => {
coderz-w marked this conversation as resolved.
Show resolved Hide resolved
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()
coderz-w marked this conversation as resolved.
Show resolved Hide resolved
});

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