diff --git a/src/Menu.tsx b/src/Menu.tsx index 14c6a9bc..754bfe9f 100644 --- a/src/Menu.tsx +++ b/src/Menu.tsx @@ -535,12 +535,12 @@ const Menu: React.FC = props => { {container} - {/* Measure menu keys */} - {/*
*/} - - {childList} - - {/*
*/} + {/* Measure menu keys. Add `display: none` to avoid some developer miss use the Menu */} +
+ + {childList} + +
); diff --git a/src/MenuItem.tsx b/src/MenuItem.tsx index ff9ad750..b48ec56a 100644 --- a/src/MenuItem.tsx +++ b/src/MenuItem.tsx @@ -135,7 +135,8 @@ const InternalMenuItem = (props: MenuItemProps) => { ): MenuInfo => { return { key: eventKey, - keyPath: connectedKeys, + // Note: For legacy code is reversed which not like other antd component + keyPath: [...connectedKeys].reverse(), item: legacyMenuItemRef.current, domEvent: e, }; diff --git a/tests/Menu.spec.js b/tests/Menu.spec.js index 6835b897..4f2b93c9 100644 --- a/tests/Menu.spec.js +++ b/tests/Menu.spec.js @@ -331,18 +331,29 @@ describe('Menu', () => { }); it('fires click event', () => { + jest.useFakeTimers(); + resetWarned(); const errorSpy = jest.spyOn(console, 'error'); const handleClick = jest.fn(); const wrapper = mount( - + 1 2 + + 3 + , ); - wrapper.find('MenuItem').first().simulate('click'); + + act(() => { + jest.runAllTimers(); + wrapper.update(); + }); + + wrapper.find('.rc-menu-item').first().simulate('click'); const info = handleClick.mock.calls[0][0]; expect(info.key).toBe('1'); expect(info.item).toBeTruthy(); @@ -351,7 +362,13 @@ describe('Menu', () => { 'Warning: `info.item` is deprecated since we will move to function component that not provides React Node instance in future.', ); + handleClick.mockReset(); + wrapper.find('.rc-menu-item').last().simulate('click'); + expect(handleClick.mock.calls[0][0].keyPath).toEqual(['3', 'parent']); + errorSpy.mockRestore(); + + jest.useRealTimers(); }); it('fires deselect event', () => { diff --git a/tests/__snapshots__/Keyboard.spec.tsx.snap b/tests/__snapshots__/Keyboard.spec.tsx.snap index 32635ef6..4eff8d3e 100644 --- a/tests/__snapshots__/Keyboard.spec.tsx.snap +++ b/tests/__snapshots__/Keyboard.spec.tsx.snap @@ -1,43 +1,49 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Menu.Keyboard no data-menu-id by init 1`] = ` - + + , + + + , + -
    +
  • -
  • +
  • +
  • -
- -
  • - -
  • - + submenu + + + + , + -
      +
    • -
    • -
    • +
        + + +
      +
    • +
    • +
    • -
    - -
  • - -
  • - + submenu + + + + , + -
      +
    • -
    • -
    • +
        + + +
      +
    • +
    • +
    • -
    - -
  • - -
  • - + submenu + + + + , + - - -
  • -
  • + +
  • + - - + 6 + + , + -
      +
    • -
    • +
    • +
    • -
    - -
  • - -
  • - + submenu + + + + , + -
      +
    • -
    • -
    • +
        + + +
      +
    • +
    • +
    • -
    - -
  • - -
  • - + submenu + + + + , + +
      + +
    + +
  • -
  • - - - + title + +
      + +
    + + , + , - "Bamboo", + , ] `;