diff --git a/src/Menu.tsx b/src/Menu.tsx index 49d1e0b2..318b0586 100644 --- a/src/Menu.tsx +++ b/src/Menu.tsx @@ -53,7 +53,7 @@ export interface MenuProps 'onClick' | 'onSelect' | 'dir' > { prefixCls?: string; - + rootClassName?: string; items?: ItemType[]; /** @deprecated Please use `items` instead */ children?: React.ReactNode; @@ -153,6 +153,7 @@ interface LegacyMenuProps extends MenuProps { const Menu = React.forwardRef((props, ref) => { const { prefixCls = 'rc-menu', + rootClassName, style, className, tabIndex = 0, @@ -518,6 +519,7 @@ const Menu = React.forwardRef((props, ref) => { [`${prefixCls}-inline-collapsed`]: mergedInlineCollapsed, [`${prefixCls}-rtl`]: isRtl, }, + rootClassName, )} dir={direction} style={style} @@ -564,6 +566,7 @@ const Menu = React.forwardRef((props, ref) => { >>>> Icon itemIcon?: RenderIconType; expandIcon?: RenderIconType; diff --git a/tests/SubMenu.spec.js b/tests/SubMenu.spec.js index 41b9bf17..8a180158 100644 --- a/tests/SubMenu.spec.js +++ b/tests/SubMenu.spec.js @@ -439,5 +439,48 @@ describe('SubMenu', () => { jest.useRealTimers(); }); + + it('should support rootClassName', () => { + const wrapper = mount( + + + + submenu7 + + + + 2 + + + 3 + + , + ); + expect(wrapper.render()).toMatchSnapshot(); + + expect( + wrapper.find('ul.rc-menu-root').at(0).hasClass('custom-className'), + ).toBe(true); + expect(wrapper.find('.rc-menu-submenu-popup').length).toBe(0); + + act(() => { + jest.runAllTimers(); + wrapper.update(); + }); + + // Enter + wrapper.find('.rc-menu-submenu-title').first().simulate('mouseEnter'); + + act(() => { + jest.runAllTimers(); + wrapper.update(); + }); + + expect( + wrapper.find('.rc-menu-submenu-popup').at(0).hasClass('custom-className'), + ).toBe(true); + + expect(wrapper.render()).toMatchSnapshot(); + }); }); /* eslint-enable */ diff --git a/tests/__snapshots__/SubMenu.spec.js.snap b/tests/__snapshots__/SubMenu.spec.js.snap new file mode 100644 index 00000000..11f7aaed --- /dev/null +++ b/tests/__snapshots__/SubMenu.spec.js.snap @@ -0,0 +1,131 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`SubMenu should support rootClassName 1`] = ` +Array [ + , +