From c523266a99cb4bfc8d792c0ff772dfeb9948d18d Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Tue, 10 Nov 2020 00:18:32 +0800 Subject: [PATCH] fix: menu some class not correct --- components/menu/SubMenu.tsx | 4 +++- components/vc-menu/SubMenu.jsx | 13 +++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/components/menu/SubMenu.tsx b/components/menu/SubMenu.tsx index 8da036938..e879eba66 100644 --- a/components/menu/SubMenu.tsx +++ b/components/menu/SubMenu.tsx @@ -3,6 +3,7 @@ import { SubMenu as VcSubMenu } from '../vc-menu'; import classNames from '../_util/classNames'; import Omit from 'omit.js'; import { getSlot } from '../_util/props-util'; +import { injectExtraPropsKey } from '../vc-menu/FunctionProvider'; export type MenuTheme = 'light' | 'dark'; @@ -19,6 +20,7 @@ export default defineComponent({ setup() { return { menuPropsContext: inject('menuPropsContext', {}), + injectExtraProps: inject(injectExtraPropsKey, () => ({})), }; }, methods: { @@ -29,7 +31,7 @@ export default defineComponent({ render() { const { $slots, $attrs } = this; - const { rootPrefixCls, popupClassName } = this.$props; + const { rootPrefixCls, popupClassName } = {...this.$props, ...this.injectExtraProps} as any; const { theme: antdMenuTheme } = this.menuPropsContext; const props = { ...this.$props, diff --git a/components/vc-menu/SubMenu.jsx b/components/vc-menu/SubMenu.jsx index 69508a998..102c67096 100644 --- a/components/vc-menu/SubMenu.jsx +++ b/components/vc-menu/SubMenu.jsx @@ -310,9 +310,9 @@ const SubMenu = { } }, - isChildrenSelected() { + isChildrenSelected(children) { const ret = { find: false }; - loopMenuItemRecursively(getSlot(this), this.$props.selectedKeys, ret); + loopMenuItemRecursively(children, this.$props.selectedKeys, ret); return ret.find; }, // isOpen () { @@ -412,10 +412,12 @@ const SubMenu = { render() { const props = { ...this.$props, ...this.$attrs }; const { onEvents } = splitAttrs(props); - const { rootPrefixCls, parentMenu } = this; + const { rootPrefixCls } = this; const isOpen = props.isOpen; const prefixCls = this.getPrefixCls(); const isInlineMode = props.mode === 'inline'; + const childrenTemp = filterEmpty(getSlot(this)); + const children = this.renderChildren(childrenTemp); const className = { [prefixCls]: true, [`${prefixCls}-${props.mode}`]: true, @@ -423,7 +425,7 @@ const SubMenu = { [this.getOpenClassName()]: isOpen, [this.getActiveClassName()]: props.active || (isOpen && !isInlineMode), [this.getDisabledClassName()]: props.disabled, - [this.getSelectedClassName()]: this.isChildrenSelected(), + [this.getSelectedClassName()]: this.isChildrenSelected(childrenTemp), }; if (!this.internalMenuId) { @@ -489,7 +491,6 @@ const SubMenu = { {icon || } ); - const children = this.renderChildren(filterEmpty(getSlot(this))); const getPopupContainer = this.parentMenu.isRootMenu ? this.parentMenu.getPopupContainer @@ -497,7 +498,7 @@ const SubMenu = { const popupPlacement = popupPlacementMap[props.mode]; const popupAlign = props.popupOffset ? { offset: props.popupOffset } : {}; let popupClassName = props.mode === 'inline' ? '' : props.popupClassName || ''; - popupClassName = `${prefixCls}-popup ${rootPrefixCls}-${parentMenu.theme} ${popupClassName}`; + popupClassName = `${prefixCls}-popup ${rootPrefixCls} ${popupClassName}`; const liProps = { ...omit(onEvents, ['onClick']), ...mouseEvents,