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 ability to overwrite Menu theme at Menu.SubMenu level. #33971

Merged
merged 19 commits into from
Feb 14, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions components/menu/SubMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { SubMenu as RcSubMenu, useFullPath } from 'rc-menu';
import classNames from 'classnames';
import omit from 'rc-util/lib/omit';
import MenuContext from './MenuContext';
import MenuContext, { MenuTheme } from './MenuContext';
import { isValidElement, cloneElement } from '../_util/reactNode';

interface TitleEventEntity {
Expand All @@ -23,10 +23,11 @@ export interface SubMenuProps {
popupOffset?: [number, number];
popupClassName?: string;
children?: React.ReactNode;
theme?: MenuTheme;
}

function SubMenu(props: SubMenuProps) {
const { popupClassName, icon, title } = props;
const { popupClassName, icon, title, theme } = props;
const context = React.useContext(MenuContext);
const { prefixCls, inlineCollapsed, antdMenuTheme } = context;

Expand Down Expand Up @@ -71,7 +72,11 @@ function SubMenu(props: SubMenuProps) {
<RcSubMenu
{...omit(props, ['icon'])}
title={titleNode}
popupClassName={classNames(prefixCls, `${prefixCls}-${antdMenuTheme}`, popupClassName)}
popupClassName={classNames(
prefixCls,
`${prefixCls}-${theme || antdMenuTheme}`,
popupClassName,
)}
/>
</MenuContext.Provider>
);
Expand Down
3 changes: 2 additions & 1 deletion components/menu/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,15 @@ More layouts with navigation: [Layout](/components/layout).
### Menu.SubMenu

| Param | Description | Type | Default value | Version |
| --- | --- | --- | --- | --- |
| --- | --- | --- | --- | --- | --- |
yoyo837 marked this conversation as resolved.
Show resolved Hide resolved
| children | Sub-menus or sub-menu items | Array&lt;MenuItem \| SubMenu> | - | |
| disabled | Whether sub-menu is disabled | boolean | false | |
| icon | Icon of sub menu | ReactNode | - | 4.2.0 |
| key | Unique ID of the sub-menu | string | - | |
| popupClassName | Sub-menu class name, not working when `mode="inline"` | string | - | |
| popupOffset | Sub-menu offset, not working when `mode="inline"` | \[number, number] | - | |
| title | Title of sub menu | ReactNode | - | |
| theme | Color theme of the sub-menu (inherits from `Menu`) | | `light` \| `dark` | - | 4.18 |
david-cord marked this conversation as resolved.
Show resolved Hide resolved
| onTitleClick | Callback executed when the sub-menu title is clicked | function({ key, domEvent }) | - | |

### Menu.ItemGroup
Expand Down