From 386f3d003fd990c8b99615d7907f95ac1b78d18d Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Sun, 1 Aug 2021 23:30:00 +0800 Subject: [PATCH] perf: update menu --- components/form/FormItem.tsx | 3 ++- components/menu/src/InlineSubMenuList.tsx | 10 +++----- components/menu/src/Menu.tsx | 4 +-- components/menu/src/SubMenu.tsx | 9 ++----- components/menu/src/hooks/useMenuContext.ts | 27 ++++++++++++++++----- 5 files changed, 30 insertions(+), 23 deletions(-) diff --git a/components/form/FormItem.tsx b/components/form/FormItem.tsx index bba61927c..08b3566bc 100644 --- a/components/form/FormItem.tsx +++ b/components/form/FormItem.tsx @@ -1,4 +1,5 @@ -import { PropType, ExtractPropTypes, ComputedRef, watch } from 'vue'; +import type { PropType, ExtractPropTypes, ComputedRef } from 'vue'; +import { watch } from 'vue'; import { defineComponent, computed, nextTick, ref, watchEffect, onBeforeUnmount } from 'vue'; import cloneDeep from 'lodash-es/cloneDeep'; import PropTypes from '../_util/vue-types'; diff --git a/components/menu/src/InlineSubMenuList.tsx b/components/menu/src/InlineSubMenuList.tsx index c3c9c3352..1d34de925 100644 --- a/components/menu/src/InlineSubMenuList.tsx +++ b/components/menu/src/InlineSubMenuList.tsx @@ -1,6 +1,7 @@ import { computed, defineComponent, ref, watch } from 'vue'; import Transition from '../../_util/transition'; import { useInjectMenu, MenuContextProvider } from './hooks/useMenuContext'; +import type { MenuMode } from './interface'; import SubMenuList from './SubMenuList'; export default defineComponent({ @@ -12,7 +13,7 @@ export default defineComponent({ keyPath: Array, }, setup(props, { slots }) { - const fixedMode = computed(() => 'inline'); + const fixedMode = computed(() => 'inline'); const { motion, mode, defaultMotions } = useInjectMenu(); const sameModeRef = computed(() => mode.value === fixedMode.value); const destroy = ref(!sameModeRef.value); @@ -43,12 +44,7 @@ export default defineComponent({ return null; } return ( - + (isMounted.value ? defaultMotions : null)), motion: computed(() => (isMounted.value ? props.motion : null)), - overflowDisabled: computed(() => undefined), + overflowDisabled: ref(undefined), onOpenChange: onInternalOpenChange, onItemClick: onInternalClick, registerMenuInfo, @@ -391,7 +391,7 @@ export default defineComponent({ // Always wrap provider to avoid sub node re-mount index > lastVisibleIndex.value) }} + overflowDisabled={index > lastVisibleIndex.value} > {child} diff --git a/components/menu/src/SubMenu.tsx b/components/menu/src/SubMenu.tsx index 0aadbd0c7..24fde493f 100644 --- a/components/menu/src/SubMenu.tsx +++ b/components/menu/src/SubMenu.tsx @@ -268,12 +268,7 @@ export default defineComponent({ onVisibleChange={onPopupVisibleChange} v-slots={{ popup: ({ visible }) => ( - + {slots.default?.()} @@ -292,7 +287,7 @@ export default defineComponent({ titleNode = {titleNode}; } return ( - + ; rtl?: ComputedRef; - locked?: Ref; - inlineCollapsed: Ref; antdMenuTheme?: ComputedRef; @@ -44,7 +44,7 @@ export interface MenuContextProps { // // Disabled disabled?: ComputedRef; // // Used for overflow only. Prevent hidden node trigger open - overflowDisabled?: ComputedRef; + overflowDisabled?: Ref; // // Active activeKeys: Ref; @@ -108,10 +108,25 @@ const MenuContextProvider = defineComponent({ name: 'MenuContextProvider', inheritAttrs: false, props: { - props: Object, + mode: { type: String as PropType, default: undefined }, + overflowDisabled: { type: Boolean, default: undefined }, + isRootMenu: { type: Boolean, default: undefined }, }, setup(props, { slots }) { - useProvideMenu({ ...useInjectMenu(), ...props.props }); + const menuContext = useInjectMenu(); + const newContext = { ...menuContext }; + watchEffect(() => { + if (props.mode !== undefined) { + newContext.mode = toRef(props, 'mode'); + } + if (props.isRootMenu !== undefined) { + newContext.isRootMenu = props.isRootMenu; + } + if (props.overflowDisabled !== undefined) { + newContext.overflowDisabled = toRef(props, 'overflowDisabled'); + } + }); + useProvideMenu(newContext); return () => slots.default?.(); }, });