From 9fc2ba8adf2935bfdaceee828f1bc51d4f5e2f39 Mon Sep 17 00:00:00 2001 From: leejimqiu Date: Wed, 16 Feb 2022 18:36:51 +0800 Subject: [PATCH 1/2] fix(menu): resolve expandType correctly --- src/menu/menu.tsx | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/menu/menu.tsx b/src/menu/menu.tsx index b6f59e86b..b295b3ed3 100644 --- a/src/menu/menu.tsx +++ b/src/menu/menu.tsx @@ -1,5 +1,5 @@ import { - defineComponent, ref, computed, provide, watchEffect, watch, onMounted, + defineComponent, ref, computed, provide, watch, onMounted, } from '@vue/composition-api'; import { prefix } from '../config'; import props from './props'; @@ -55,11 +55,6 @@ export default defineComponent({ const emitExpand = deliver('expand'); const emitCollapse = deliver('collapsed'); - watchEffect(() => { - mode.value = props.collapsed ? 'popup' : 'normal'; - emitCollapse(mode.value); - }); - const vMenu = new VMenu({ isMutex: isMutex.value, expandValues: expandValues.value }); provide('TdMenu', { activeValue, @@ -81,7 +76,8 @@ export default defineComponent({ const index = expanded.indexOf(value); if (type === 'add') { - if (index === -1) { // 可能初始expanded里包含了该value + if (index === -1) { + // 可能初始expanded里包含了该value expanded.push(value); } } else if (type === 'remove') { @@ -106,6 +102,19 @@ export default defineComponent({ }; watch(() => props.value, updateActiveValues); watch(() => props.defaultValue, updateActiveValues); + watch( + () => props.expandType, + (value) => { + mode.value = props.collapsed ? 'popup' : value; + }, + ); + watch( + () => props.collapsed, + (collapsed) => { + mode.value = collapsed ? 'popup' : props.expandType; + emitCollapse(collapsed); + }, + ); // timelifes onMounted(() => { @@ -130,11 +139,9 @@ export default defineComponent({ return (
- {logo && (
{logo}
)} -
    - {renderContent(this, 'default', 'content')} -
- {operations && (
{operations}
)} + {logo &&
{logo}
} +
    {renderContent(this, 'default', 'content')}
+ {operations &&
{operations}
}
); From 4b3f5d0a525f1f2df48d8a2b3471b31d139ed433 Mon Sep 17 00:00:00 2001 From: leejimqiu Date: Thu, 17 Feb 2022 11:29:08 +0800 Subject: [PATCH 2/2] fix(menu): remove collapsed event & resolve test --- examples/menu/menu.md | 2 -- src/menu/head-menu-props.ts | 1 - src/menu/menu-group-props.ts | 1 - src/menu/menu-item-props.ts | 1 - src/menu/menu.tsx | 20 +++++--------------- src/menu/props.ts | 7 ++----- src/menu/submenu-props.ts | 1 - src/menu/type.ts | 27 ++++++++++++++------------- 8 files changed, 21 insertions(+), 39 deletions(-) diff --git a/examples/menu/menu.md b/examples/menu/menu.md index 51b75175f..3a8b43f1d 100644 --- a/examples/menu/menu.md +++ b/examples/menu/menu.md @@ -24,7 +24,6 @@ value | String / Number | - | 激活菜单项。支持语法糖 `.sync`。TS 类 defaultValue | String / Number | - | 激活菜单项。非受控属性。TS 类型:`MenuValue` `type MenuValue = string | number`。[详细类型定义](https://github.com/Tencent/tdesign-vue/tree/develop/src/menu/type.ts) | N width | String / Number / Array | '232px' | 菜单宽度。值类型为数组时,分别表示菜单展开和折叠的宽度。[ 展开时的宽度, 折叠时的宽度 ],示例:['200px', '80px']。TS 类型:`string | number | Array` | N onChange | Function | | TS 类型:`(value: MenuValue) => void`
激活菜单项发生变化时触发 | N -onCollapsed | Function | | TS 类型:`(options: { collapsed: boolean; e?: MouseEvent }) => void`
侧边栏导航展开/收起发生变化时触发 | N onExpand | Function | | TS 类型:`(value: Array) => void`
展开的菜单项发生变化时触发 | N ### Menu Events @@ -32,7 +31,6 @@ onExpand | Function | | TS 类型:`(value: Array) => void`
展 名称 | 参数 | 描述 -- | -- | -- change | `(value: MenuValue)` | 激活菜单项发生变化时触发 -collapsed | `(options: { collapsed: boolean; e?: MouseEvent })` | 侧边栏导航展开/收起发生变化时触发 expand | `(value: Array)` | 展开的菜单项发生变化时触发 ### HeadMenu Props diff --git a/src/menu/head-menu-props.ts b/src/menu/head-menu-props.ts index 721aeea84..8187ad679 100644 --- a/src/menu/head-menu-props.ts +++ b/src/menu/head-menu-props.ts @@ -2,7 +2,6 @@ /** * 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC - * updated at 2021-11-19 10:44:26 * */ import { TdHeadMenuProps } from '../menu/type'; diff --git a/src/menu/menu-group-props.ts b/src/menu/menu-group-props.ts index b4ebfbe48..7abe7a083 100644 --- a/src/menu/menu-group-props.ts +++ b/src/menu/menu-group-props.ts @@ -2,7 +2,6 @@ /** * 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC - * updated at 2021-11-19 10:44:26 * */ import { TdMenuGroupProps } from '../menu/type'; diff --git a/src/menu/menu-item-props.ts b/src/menu/menu-item-props.ts index 1fe0d69b8..4babf9de9 100644 --- a/src/menu/menu-item-props.ts +++ b/src/menu/menu-item-props.ts @@ -2,7 +2,6 @@ /** * 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC - * updated at 2021-11-19 10:44:26 * */ import { TdMenuItemProps } from '../menu/type'; diff --git a/src/menu/menu.tsx b/src/menu/menu.tsx index b295b3ed3..7e5a55e90 100644 --- a/src/menu/menu.tsx +++ b/src/menu/menu.tsx @@ -1,5 +1,5 @@ import { - defineComponent, ref, computed, provide, watch, onMounted, + defineComponent, ref, computed, watchEffect, provide, watch, onMounted, } from '@vue/composition-api'; import { prefix } from '../config'; import props from './props'; @@ -53,7 +53,10 @@ export default defineComponent({ }; const emitChange = deliver('change'); const emitExpand = deliver('expand'); - const emitCollapse = deliver('collapsed'); + + watchEffect(() => { + mode.value = props.collapsed ? 'popup' : props.expandType; + }); const vMenu = new VMenu({ isMutex: isMutex.value, expandValues: expandValues.value }); provide('TdMenu', { @@ -102,19 +105,6 @@ export default defineComponent({ }; watch(() => props.value, updateActiveValues); watch(() => props.defaultValue, updateActiveValues); - watch( - () => props.expandType, - (value) => { - mode.value = props.collapsed ? 'popup' : value; - }, - ); - watch( - () => props.collapsed, - (collapsed) => { - mode.value = collapsed ? 'popup' : props.expandType; - emitCollapse(collapsed); - }, - ); // timelifes onMounted(() => { diff --git a/src/menu/props.ts b/src/menu/props.ts index 5bf6280d3..bdefbe9f4 100644 --- a/src/menu/props.ts +++ b/src/menu/props.ts @@ -2,7 +2,6 @@ /** * 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC - * updated at 2021-11-23 10:43:39 * */ import { TdMenuProps } from './type'; @@ -11,11 +10,11 @@ import { PropType } from 'vue'; export default { /** 是否收起菜单 */ collapsed: Boolean, - /** 展开的子菜单集合 */ + /** 子菜单展开的导航集合 */ expanded: { type: Array as PropType, }, - /** 展开的子菜单集合,非受控属性 */ + /** 子菜单展开的导航集合,非受控属性 */ defaultExpanded: { type: Array as PropType, }, @@ -60,8 +59,6 @@ export default { }, /** 激活菜单项发生变化时触发 */ onChange: Function as PropType, - /** 侧边栏导航展开/收起发生变化时触发 */ - onCollapsed: Function as PropType, /** 展开的菜单项发生变化时触发 */ onExpand: Function as PropType, }; diff --git a/src/menu/submenu-props.ts b/src/menu/submenu-props.ts index 14032620a..7426df395 100644 --- a/src/menu/submenu-props.ts +++ b/src/menu/submenu-props.ts @@ -2,7 +2,6 @@ /** * 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC - * updated at 2021-11-19 10:44:26 * */ import { TdSubmenuProps } from '../menu/type'; diff --git a/src/menu/type.ts b/src/menu/type.ts index 707501421..c5cc6d64a 100644 --- a/src/menu/type.ts +++ b/src/menu/type.ts @@ -2,7 +2,6 @@ /** * 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC - * updated at 2021-11-23 10:43:39 * */ import { TNode } from '../common'; @@ -14,11 +13,11 @@ export interface TdMenuProps { */ collapsed?: boolean; /** - * 展开的子菜单集合 + * 子菜单展开的导航集合 */ expanded?: Array; /** - * 展开的子菜单集合,非受控属性 + * 子菜单展开的导航集合,非受控属性 */ defaultExpanded?: Array; /** @@ -61,15 +60,11 @@ export interface TdMenuProps { * 激活菜单项发生变化时触发 */ onChange?: (value: MenuValue) => void; - /** - * 侧边栏导航展开/收起发生变化时触发 - */ - onCollapsed?: (options: { collapsed: boolean; e?: MouseEvent }) => void; /** * 展开的菜单项发生变化时触发 */ onExpand?: (value: Array) => void; -}; +} export interface TdHeadMenuProps { /** @@ -114,7 +109,7 @@ export interface TdHeadMenuProps { * 展开的菜单项发生变化时触发 */ onExpand?: (value: Array) => void; -}; +} export interface TdSubmenuProps { /** @@ -141,7 +136,7 @@ export interface TdSubmenuProps { * 菜单项唯一标识 */ value?: MenuValue; -}; +} export interface TdMenuItemProps { /** @@ -190,17 +185,23 @@ export interface TdMenuItemProps { * 点击时触发 */ onClick?: (context: { e: MouseEvent }) => void; -}; +} export interface TdMenuGroupProps { /** * 菜单组标题 */ title?: string | TNode; -}; +} export type MenuValue = string | number; -export interface MenuRoute { path?: string; name?: string; hash?: string; query?: MenuQueryData; params?: MenuQueryData }; +export interface MenuRoute { + path?: string; + name?: string; + hash?: string; + query?: MenuQueryData; + params?: MenuQueryData; +} export type MenuQueryData = { [key: string]: string | string[] };