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

feat: add rootClassName #445

Merged
merged 1 commit into from
Apr 8, 2022
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
5 changes: 4 additions & 1 deletion src/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export interface MenuProps
'onClick' | 'onSelect' | 'dir'
> {
prefixCls?: string;

rootClassName?: string;
items?: ItemType[];
/** @deprecated Please use `items` instead */
children?: React.ReactNode;
Expand Down Expand Up @@ -153,6 +153,7 @@ interface LegacyMenuProps extends MenuProps {
const Menu = React.forwardRef<MenuRef, MenuProps>((props, ref) => {
const {
prefixCls = 'rc-menu',
rootClassName,
style,
className,
tabIndex = 0,
Expand Down Expand Up @@ -518,6 +519,7 @@ const Menu = React.forwardRef<MenuRef, MenuProps>((props, ref) => {
[`${prefixCls}-inline-collapsed`]: mergedInlineCollapsed,
[`${prefixCls}-rtl`]: isRtl,
},
rootClassName,
)}
dir={direction}
style={style}
Expand Down Expand Up @@ -564,6 +566,7 @@ const Menu = React.forwardRef<MenuRef, MenuProps>((props, ref) => {
<IdContext.Provider value={uuid}>
<MenuContextProvider
prefixCls={prefixCls}
rootClassName={rootClassName}
mode={mergedMode}
openKeys={mergedOpenKeys}
rtl={isRtl}
Expand Down
2 changes: 2 additions & 0 deletions src/SubMenu/PopupTrigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default function PopupTrigger({
builtinPlacements,
triggerSubMenuAction,
forceSubMenuRender,
rootClassName,

// Motion
motion,
Expand Down Expand Up @@ -90,6 +91,7 @@ export default function PopupTrigger({
[`${prefixCls}-rtl`]: rtl,
},
popupClassName,
rootClassName,
)}
stretch={mode === 'horizontal' ? 'minWidth' : null}
getPopupContainer={getPopupContainer}
Expand Down
1 change: 1 addition & 0 deletions src/context/MenuContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {

export interface MenuContextProps {
prefixCls: string;
rootClassName?: string;
openKeys: string[];
rtl?: boolean;

Expand Down
2 changes: 2 additions & 0 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export interface SubMenuType extends ItemSharedProps {

key: string;

rootClassName?: string;

// >>>>> Icon
itemIcon?: RenderIconType;
expandIcon?: RenderIconType;
Expand Down
43 changes: 43 additions & 0 deletions tests/SubMenu.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,5 +439,48 @@ describe('SubMenu', () => {

jest.useRealTimers();
});

it('should support rootClassName', () => {
const wrapper = mount(
<Menu rootClassName="custom-className" defaultOpenKeys={['1', '1-1']}>
<SubMenu key="1" title="submenu1">
<MenuItem key="1-1" role="option">
submenu7
</MenuItem>
</SubMenu>
<MenuItem key="2" role="option">
2
</MenuItem>
<MenuItem key="3" role="option">
3
</MenuItem>
</Menu>,
);
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 */
131 changes: 131 additions & 0 deletions tests/__snapshots__/SubMenu.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SubMenu should support rootClassName 1`] = `
Array [
<ul
class="rc-menu rc-menu-root rc-menu-vertical custom-className"
data-menu-list="true"
role="menu"
tabindex="0"
>
<li
class="rc-menu-submenu rc-menu-submenu-vertical rc-menu-submenu-open"
role="none"
>
<div
aria-controls="rc-menu-uuid-test-1-popup"
aria-expanded="true"
aria-haspopup="true"
class="rc-menu-submenu-title"
data-menu-id="rc-menu-uuid-test-1"
role="menuitem"
tabindex="-1"
title="submenu1"
>
submenu1
<i
class="rc-menu-submenu-arrow"
/>
</div>
</li>
<li
aria-selected="false"
class="rc-menu-item"
data-menu-id="rc-menu-uuid-test-2"
role="option"
tabindex="-1"
>
2
</li>
<li
aria-selected="false"
class="rc-menu-item"
data-menu-id="rc-menu-uuid-test-3"
role="option"
tabindex="-1"
>
3
</li>
</ul>,
<div
aria-hidden="true"
style="display: none;"
/>,
]
`;

exports[`SubMenu should support rootClassName 2`] = `
Array [
<ul
class="rc-menu rc-menu-root rc-menu-vertical custom-className"
data-menu-list="true"
role="menu"
tabindex="0"
>
<li
class="rc-menu-submenu rc-menu-submenu-vertical rc-menu-submenu-open rc-menu-submenu-active"
role="none"
>
<div
aria-controls="rc-menu-uuid-test-1-popup"
aria-expanded="true"
aria-haspopup="true"
class="rc-menu-submenu-title"
data-menu-id="rc-menu-uuid-test-1"
role="menuitem"
tabindex="-1"
title="submenu1"
>
submenu1
<i
class="rc-menu-submenu-arrow"
/>
</div>
<div>
<div
class="rc-menu-submenu rc-menu-submenu-popup custom-className"
style="opacity: 0; pointer-events: none;"
>
<ul
class="rc-menu rc-menu-sub rc-menu-vertical"
data-menu-list="true"
id="rc-menu-uuid-test-1-popup"
>
<li
aria-selected="false"
class="rc-menu-item"
data-menu-id="rc-menu-uuid-test-1-1"
role="option"
tabindex="-1"
>
submenu7
</li>
</ul>
</div>
</div>
</li>
<li
aria-selected="false"
class="rc-menu-item"
data-menu-id="rc-menu-uuid-test-2"
role="option"
tabindex="-1"
>
2
</li>
<li
aria-selected="false"
class="rc-menu-item"
data-menu-id="rc-menu-uuid-test-3"
role="option"
tabindex="-1"
>
3
</li>
</ul>,
<div
aria-hidden="true"
style="display: none;"
/>,
]
`;