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: support for submenu custom styles #645

Merged
merged 8 commits into from
Jul 1, 2023
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ ReactDOM.render(
<td></td>
<td>additional css class of root dom node</td>
</tr>
<tr>
<td>popupStyle</td>
<td>CSSProperties</td>
<td></td>
<td>additional css style of root dom node</td>
</tr>
<tr>
<td>title</td>
<td>String/ReactElement</td>
Expand Down
3 changes: 3 additions & 0 deletions src/SubMenu/PopupTrigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface PopupTriggerProps {
visible: boolean;
children: React.ReactElement;
popup: React.ReactNode;
popupStyle?: React.CSSProperties;
popupClassName?: string;
popupOffset?: number[];
disabled: boolean;
Expand All @@ -32,6 +33,7 @@ export default function PopupTrigger({
visible,
children,
popup,
popupStyle,
popupClassName,
popupOffset,
disabled,
Expand Down Expand Up @@ -108,6 +110,7 @@ export default function PopupTrigger({
popupPlacement={popupPlacement}
popupVisible={innerVisible}
popup={popup}
popupStyle={popupStyle}
popupAlign={popupOffset && { offset: popupOffset }}
action={disabled ? [] : [triggerSubMenuAction]}
mouseEnterDelay={subMenuOpenDelay}
Expand Down
2 changes: 2 additions & 0 deletions src/SubMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const InternalSubMenu = (props: SubMenuProps) => {
// Popup
popupClassName,
popupOffset,
popupStyle,

// Events
onClick,
Expand Down Expand Up @@ -280,6 +281,7 @@ const InternalSubMenu = (props: SubMenuProps) => {
visible={!internalPopupClose && open && mode !== 'inline'}
popupClassName={popupClassName}
popupOffset={popupOffset}
popupStyle={popupStyle}
popup={
<MenuContextProvider
// Special handle of horizontal mode
Expand Down
1 change: 1 addition & 0 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface SubMenuType extends ItemSharedProps {
// >>>>> Popup
popupClassName?: string;
popupOffset?: number[];
popupStyle?: React.CSSProperties;

// >>>>> Events
onClick?: MenuClickEventHandler;
Expand Down
23 changes: 21 additions & 2 deletions tests/SubMenu.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Menu, { MenuItem, SubMenu } from '../src';
import { isActive, last } from './util';

jest.mock('@rc-component/trigger', () => {
const react = require('react');
const react = require('react');
let Trigger = jest.requireActual('@rc-component/trigger/lib/mock');
Trigger = Trigger.default || Trigger;

Expand All @@ -17,7 +17,7 @@ jest.mock('@rc-component/trigger', () => {
});

jest.mock('../src/SubMenu/PopupTrigger', () => {
const react = require('react');
const react = require('react');
let PopupTrigger = jest.requireActual('../src/SubMenu/PopupTrigger');
PopupTrigger = PopupTrigger.default || PopupTrigger;

Expand Down Expand Up @@ -480,5 +480,24 @@ describe('SubMenu', () => {

expect(container.children).toMatchSnapshot();
});

it('submenu should support popupStyle', () => {
const { container } = render(
<Menu>
<SubMenu
key="s1"
title="submenu1"
popupStyle={{ zIndex: 100, width: 150 }}
>
<MenuItem key="s1-1">1</MenuItem>
</SubMenu>
</Menu>,
);

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');
});
});
/* eslint-enable */