Skip to content

Commit 4dd6f7a

Browse files
liujupingJackLian
authored andcommitted
feat: update comtext menu component
1 parent 7f2b287 commit 4dd6f7a

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

packages/shell/src/components/context-menu.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
import { createContextMenu, parseContextMenuAsReactNode, parseContextMenuProperties } from '@alilc/lowcode-utils';
22
import { engineConfig } from '@alilc/lowcode-editor-core';
33
import { IPublicModelPluginContext, IPublicTypeContextMenuAction } from '@alilc/lowcode-types';
4-
import React from 'react';
4+
import React, { useCallback } from 'react';
55

66
export function ContextMenu({ children, menus, pluginContext }: {
77
menus: IPublicTypeContextMenuAction[];
88
children: React.ReactElement[] | React.ReactElement;
99
pluginContext: IPublicModelPluginContext;
1010
}): React.ReactElement<any, string | React.JSXElementConstructor<any>> {
11-
if (!engineConfig.get('enableContextMenu')) {
12-
return (
13-
<>{ children }</>
14-
);
15-
}
16-
17-
const handleContextMenu = (event: React.MouseEvent) => {
11+
const handleContextMenu = useCallback((event: React.MouseEvent) => {
1812
event.preventDefault();
1913
event.stopPropagation();
2014

@@ -32,7 +26,19 @@ export function ContextMenu({ children, menus, pluginContext }: {
3226
}
3327

3428
destroyFn = createContextMenu(children, { event });
35-
};
29+
}, [menus]);
30+
31+
if (!engineConfig.get('enableContextMenu')) {
32+
return (
33+
<>{ children }</>
34+
);
35+
}
36+
37+
if (!menus || !menus.length) {
38+
return (
39+
<>{ children }</>
40+
);
41+
}
3642

3743
// 克隆 children 并添加 onContextMenu 事件处理器
3844
const childrenWithContextMenu = React.Children.map(children, (child) =>

0 commit comments

Comments
 (0)