From d3ff73a94fa6445bdc6f8692cd47a1e5c0d69488 Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Mon, 29 May 2023 13:58:36 +0800 Subject: [PATCH] fix: overflowed submenu should have classes with customized class (#42692) --- components/menu/__tests__/index.test.tsx | 30 +++++++++++++++++++++--- components/menu/menu.tsx | 27 ++++++++++++--------- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/components/menu/__tests__/index.test.tsx b/components/menu/__tests__/index.test.tsx index c1158d87c7..4a6c5c6c87 100644 --- a/components/menu/__tests__/index.test.tsx +++ b/components/menu/__tests__/index.test.tsx @@ -8,12 +8,13 @@ import { import React, { useMemo, useState } from 'react'; import type { MenuProps, MenuRef } from '..'; import Menu from '..'; +import { TriggerMockContext } from '../../../tests/shared/demoTestContext'; import mountTest from '../../../tests/shared/mountTest'; import rtlTest from '../../../tests/shared/rtlTest'; import { act, fireEvent, render } from '../../../tests/utils'; -import Layout from '../../layout'; import initCollapseMotion from '../../_util/motion'; import { noop } from '../../_util/warning'; +import Layout from '../../layout'; Object.defineProperty(globalThis, 'IS_REACT_ACT_ENVIRONMENT', { writable: true, @@ -824,7 +825,7 @@ describe('Menu', () => { const onOpen = jest.fn(); const onClose = jest.fn(); const Demo: React.FC = () => { - const menuProps = useMemo(() => ({ onOpen, onClose }) as MenuProps, []); + const menuProps = useMemo(() => ({ onOpen, onClose } as MenuProps), []); return ( { it('should keep selectedKeys in state when collapsed to 0px', () => { jest.useFakeTimers(); const Demo: React.FC = (props) => { - const menuProps = useMemo(() => ({ collapsedWidth: 0 }) as MenuProps, []); + const menuProps = useMemo(() => ({ collapsedWidth: 0 } as MenuProps), []); return ( { '0', ); }); + + it('Overflow indicator className should not override menu class', () => { + const { container } = render( + + node.parentElement!} + /> + , + ); + expect(container.querySelector('.ant-menu.ant-menu-light.custom-popover')).toBeTruthy(); + }); }); diff --git a/components/menu/menu.tsx b/components/menu/menu.tsx index c8dee4d9e3..07a9281e74 100644 --- a/components/menu/menu.tsx +++ b/components/menu/menu.tsx @@ -1,22 +1,22 @@ +import EllipsisOutlined from '@ant-design/icons/EllipsisOutlined'; +import classNames from 'classnames'; import type { MenuProps as RcMenuProps, MenuRef as RcMenuRef } from 'rc-menu'; import RcMenu from 'rc-menu'; +import useEvent from 'rc-util/lib/hooks/useEvent'; +import omit from 'rc-util/lib/omit'; import * as React from 'react'; import { forwardRef } from 'react'; -import omit from 'rc-util/lib/omit'; -import useEvent from 'rc-util/lib/hooks/useEvent'; -import classNames from 'classnames'; -import EllipsisOutlined from '@ant-design/icons/EllipsisOutlined'; -import warning from '../_util/warning'; import initCollapseMotion from '../_util/motion'; import { cloneElement } from '../_util/reactNode'; -import type { SiderContextProps } from '../layout/Sider'; +import warning from '../_util/warning'; import { ConfigContext } from '../config-provider'; -import useStyle from './style'; +import type { SiderContextProps } from '../layout/Sider'; +import type { MenuContextProps, MenuTheme } from './MenuContext'; +import MenuContext from './MenuContext'; import OverrideContext from './OverrideContext'; -import useItems from './hooks/useItems'; import type { ItemType } from './hooks/useItems'; -import MenuContext from './MenuContext'; -import type { MenuTheme, MenuContextProps } from './MenuContext'; +import useItems from './hooks/useItems'; +import useStyle from './style'; export interface MenuProps extends Omit { theme?: MenuTheme; @@ -59,6 +59,7 @@ const InternalMenu = forwardRef((props, ref) => { mode, selectable, onClick, + overflowedIndicatorPopupClassName, ...restProps } = props; @@ -152,7 +153,11 @@ const InternalMenu = forwardRef((props, ref) => { } - overflowedIndicatorPopupClassName={classNames(prefixCls, `${prefixCls}-${theme}`)} + overflowedIndicatorPopupClassName={classNames( + prefixCls, + `${prefixCls}-${theme}`, + overflowedIndicatorPopupClassName, + )} mode={mergedMode} selectable={mergedSelectable} onClick={onItemClick}