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

fix(menu): resolve expandType correctly #428

Merged
merged 2 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions examples/menu/menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ 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<string | number>` | N
onChange | Function | | TS 类型:`(value: MenuValue) => void`<br/>激活菜单项发生变化时触发 | N
onCollapsed | Function | | TS 类型:`(options: { collapsed: boolean; e?: MouseEvent }) => void`<br/>侧边栏导航展开/收起发生变化时触发 | N
chaishi marked this conversation as resolved.
Show resolved Hide resolved
onExpand | Function | | TS 类型:`(value: Array<MenuValue>) => void`<br/>展开的菜单项发生变化时触发 | N

### Menu Events

名称 | 参数 | 描述
-- | -- | --
change | `(value: MenuValue)` | 激活菜单项发生变化时触发
collapsed | `(options: { collapsed: boolean; e?: MouseEvent })` | 侧边栏导航展开/收起发生变化时触发
expand | `(value: Array<MenuValue>)` | 展开的菜单项发生变化时触发

### HeadMenu Props
Expand Down
1 change: 0 additions & 1 deletion src/menu/head-menu-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

/**
* 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC
* updated at 2021-11-19 10:44:26
* */

import { TdHeadMenuProps } from '../menu/type';
Expand Down
1 change: 0 additions & 1 deletion src/menu/menu-group-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

/**
* 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC
* updated at 2021-11-19 10:44:26
* */

import { TdMenuGroupProps } from '../menu/type';
Expand Down
1 change: 0 additions & 1 deletion src/menu/menu-item-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

/**
* 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC
* updated at 2021-11-19 10:44:26
* */

import { TdMenuItemProps } from '../menu/type';
Expand Down
17 changes: 7 additions & 10 deletions src/menu/menu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
defineComponent, ref, computed, provide, watchEffect, watch, onMounted,
defineComponent, ref, computed, watchEffect, provide, watch, onMounted,
} from '@vue/composition-api';
import { prefix } from '../config';
import props from './props';
Expand Down Expand Up @@ -53,11 +53,9 @@ export default defineComponent({
};
const emitChange = deliver('change');
const emitExpand = deliver('expand');
const emitCollapse = deliver('collapsed');

watchEffect(() => {
mode.value = props.collapsed ? 'popup' : 'normal';
emitCollapse(mode.value);
mode.value = props.collapsed ? 'popup' : props.expandType;
});

const vMenu = new VMenu({ isMutex: isMutex.value, expandValues: expandValues.value });
Expand All @@ -81,7 +79,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') {
Expand Down Expand Up @@ -130,11 +129,9 @@ export default defineComponent({
return (
<div class={this.menuClass} style={this.styles}>
<div class={`${prefix}-default-menu__inner`}>
{logo && (<div class={`${prefix}-menu__logo`}>{logo}</div>)}
<ul class={this.innerClasses}>
{renderContent(this, 'default', 'content')}
</ul>
{operations && (<div class={`${prefix}-menu__operations`}>{operations}</div>)}
{logo && <div class={`${prefix}-menu__logo`}>{logo}</div>}
<ul class={this.innerClasses}>{renderContent(this, 'default', 'content')}</ul>
{operations && <div class={`${prefix}-menu__operations`}>{operations}</div>}
</div>
</div>
);
Expand Down
7 changes: 2 additions & 5 deletions src/menu/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

/**
* 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC
* updated at 2021-11-23 10:43:39
* */

import { TdMenuProps } from './type';
Expand All @@ -11,11 +10,11 @@ import { PropType } from 'vue';
export default {
/** 是否收起菜单 */
collapsed: Boolean,
/** 展开的子菜单集合 */
/** 子菜单展开的导航集合 */
expanded: {
type: Array as PropType<TdMenuProps['expanded']>,
},
/** 展开的子菜单集合,非受控属性 */
/** 子菜单展开的导航集合,非受控属性 */
defaultExpanded: {
type: Array as PropType<TdMenuProps['defaultExpanded']>,
},
Expand Down Expand Up @@ -60,8 +59,6 @@ export default {
},
/** 激活菜单项发生变化时触发 */
onChange: Function as PropType<TdMenuProps['onChange']>,
/** 侧边栏导航展开/收起发生变化时触发 */
onCollapsed: Function as PropType<TdMenuProps['onCollapsed']>,
/** 展开的菜单项发生变化时触发 */
onExpand: Function as PropType<TdMenuProps['onExpand']>,
};
1 change: 0 additions & 1 deletion src/menu/submenu-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

/**
* 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC
* updated at 2021-11-19 10:44:26
* */

import { TdSubmenuProps } from '../menu/type';
Expand Down
27 changes: 14 additions & 13 deletions src/menu/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

/**
* 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC
* updated at 2021-11-23 10:43:39
* */

import { TNode } from '../common';
Expand All @@ -14,11 +13,11 @@ export interface TdMenuProps {
*/
collapsed?: boolean;
/**
* 展开的子菜单集合
* 子菜单展开的导航集合
*/
expanded?: Array<MenuValue>;
/**
* 展开的子菜单集合,非受控属性
* 子菜单展开的导航集合,非受控属性
*/
defaultExpanded?: Array<MenuValue>;
/**
Expand Down Expand Up @@ -61,15 +60,11 @@ export interface TdMenuProps {
* 激活菜单项发生变化时触发
*/
onChange?: (value: MenuValue) => void;
/**
* 侧边栏导航展开/收起发生变化时触发
*/
onCollapsed?: (options: { collapsed: boolean; e?: MouseEvent }) => void;
/**
* 展开的菜单项发生变化时触发
*/
onExpand?: (value: Array<MenuValue>) => void;
};
}

export interface TdHeadMenuProps {
/**
Expand Down Expand Up @@ -114,7 +109,7 @@ export interface TdHeadMenuProps {
* 展开的菜单项发生变化时触发
*/
onExpand?: (value: Array<MenuValue>) => void;
};
}

export interface TdSubmenuProps {
/**
Expand All @@ -141,7 +136,7 @@ export interface TdSubmenuProps {
* 菜单项唯一标识
*/
value?: MenuValue;
};
}

export interface TdMenuItemProps {
/**
Expand Down Expand Up @@ -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[] };