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

feat(FMenu): 增加 disabled 配置项 #868

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 0 deletions components/menu/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface MenuOption {
icon: () => VNodeChild;
children: MenuOption[];
isGroup: boolean;
disabled: boolean;
}

export interface MenuItemType {
Expand All @@ -15,4 +16,5 @@ export interface MenuItemType {
children: MenuItemType[];
isOpened: Ref<boolean>;
isActive: Ref<boolean>;
isDisabled: Ref<boolean>;
}
2 changes: 1 addition & 1 deletion components/menu/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default defineComponent({
isFunction(item.label) ? item.label() : item.label;
// 没有子菜单
if (!item.children) {
return <MenuItem value={item.value} v-slots={itemSlots} />;
return <MenuItem value={item.value} disabled={item.disabled} v-slots={itemSlots} />;
}
// 分组
if (item.isGroup) {
Expand Down
11 changes: 10 additions & 1 deletion components/menu/menuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const menuItemProps = {
required: true,
},
label: String,
disabled: Boolean,
} as const;

export type MenuItemProps = ExtractPublicPropTypes<typeof menuItemProps>;
Expand All @@ -38,6 +39,7 @@ export default defineComponent({
required: true,
},
label: String,
disabled: Boolean,
} satisfies ComponentObjectPropsOptions,
setup(props, { slots }) {
const instance = getCurrentInstance();
Expand All @@ -62,11 +64,15 @@ export default defineComponent({
const isActive = computed(
() => rootMenu.currentValue.value === props.value,
);
const isDisabled = computed(
() => props.disabled === true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里直接返回 props.disabled 即可

);
const menuItem = {
uid: instance.uid,
type: 'menu',
value: props.value,
isActive,
isDisabled,
};
onMounted(() => {
parentMenu.addChild(menuItem);
Expand All @@ -75,11 +81,14 @@ export default defineComponent({
parentMenu.removeChild(menuItem);
});
const classList = computed(() =>
[prefixCls, isActive.value && 'is-active']
[prefixCls, isActive.value && 'is-active', isDisabled.value && 'is-disabled']
.filter(Boolean)
.join(' '),
);
const handleClick = () => {
if (isDisabled.value) {
return;
}
rootMenu.clickMenuItem(props.value);
handleItemClick();
};
Expand Down
8 changes: 8 additions & 0 deletions components/menu/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@
transition: all @animation-duration-base @ease-base-in;
}
}
&.is-disabled {
&:hover {
cursor: not-allowed;
}
.@{menu-item-prefix-cls}-wrapper {
color: var(--f-text-color-secondary);
}
}
}

.@{menu-group-prefix-cls} {
Expand Down
4 changes: 2 additions & 2 deletions docs/.vitepress/components/menu/common.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<template #label>我是标题</template>
<f-menu-group>
<template #label>华中地区</template>
<f-menu-item value="1.1">
<f-menu-item value="1.1" disabled>
<template #label>湖南</template>
</f-menu-item>
<f-sub-menu label="湖北">
Expand All @@ -33,7 +33,7 @@
<AppstoreOutlined />
</template>
<template #label>人群管理</template>
<f-menu-item value="2.1">
<f-menu-item value="2.1" :disabled="true">
<template #label>富高帅</template>
</f-menu-item>
<f-menu-item value="2.2">
Expand Down
11 changes: 6 additions & 5 deletions docs/.vitepress/components/menu/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ app.use(FMenu);

## 代码演示


### 水平方向

:::demo
Expand Down Expand Up @@ -124,10 +123,11 @@ customContainer.vue

## MenuItem Props

| 属性 | 说明 | 类型 | 默认值 |
| ----- | ---------- | ------ | ------ |
| value | 唯一标志 | string | `null` |
| label | 菜单的标题 | string | `-` |
| 属性 | 说明 | 类型 | 默认值 |
| -------- | -------------- | ------- | ------- |
| value | 唯一标志 | string | `null` |
| label | 菜单的标题 | string | `-` |
| disabled | 是否禁用菜单项 | boolean | `false` |

## MenuItem Slots

Expand All @@ -145,3 +145,4 @@ customContainer.vue
| icon | 菜单项的图标 | ()=> VNodeChild |
| children | 子选项,当存在子选项时渲染为子菜单或者分组菜单 | `Array<MenuOption>` |
| isGroup | 是否是分组 | boolean |
| disabled | 是否禁用 | boolean |
1 change: 1 addition & 0 deletions docs/.vitepress/components/menu/options.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export default {
{
value: '1.3',
label: '深圳',
disabled: true,
},
{
value: '1.4',
Expand Down
2 changes: 1 addition & 1 deletion docs/.vitepress/components/menu/vertical.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</template>
<f-menu-group>
<template #label>华中地区</template>
<f-menu-item value="1.1">
<f-menu-item value="1.1" disabled>
<template #label>湖南</template>
</f-menu-item>
<f-sub-menu label="湖北">
Expand Down