antvis/G6

Menu插件不管点击菜单的任何地方,菜单都会隐藏 #5346

Ourydy posted onGitHub

G6 版本

4.x

问题描述

使用Menu插件时,不管点击菜单的任何地方,菜单都会隐藏,能不能在handleMenuClick回调函数中根据点击的菜单项来控制菜单的显示隐藏

重现链接

重现步骤

预期行为

在handleMenuClick回调函数中根据点击的菜单项来控制菜单的显示隐藏

平台

  • 操作系统: [macOS, Windows, Linux, React Native ...]
  • 网页浏览器: [Google Chrome, Safari, Firefox]
  • G6 版本: [4.8.20]

屏幕截图或视频(可选)

No response

补充说明(可选)

No response


Hi @Ourydy, Please star this repo if you find it useful! Thanks :star:! 你好 @Ourydy。如果该仓库对你有用,可以 star 一下,感谢你的 :star:!

posted by github-actions[bot] over 1 year ago

方便给一个案例用于调试吗?

posted by hustcc about 1 year ago

方便给一个案例用于调试吗?

import G6 from "@antv/g6";

const data = {
  nodes: [
    {
      id: "node1",
      x: 150,
      y: 50,
      label: "node1",
    },
    {
      id: "node2",
      x: 200,
      y: 150,
      label: "node2",
    },
    {
      id: "node3",
      x: 100,
      y: 150,
      label: "node3",
    },
  ],
  edges: [
    {
      source: "node1",
      target: "node2",
    },
    {
      source: "node2",
      target: "node3",
    },
    {
      source: "node3",
      target: "node1",
    },
  ],
};

const contextMenu = new G6.Menu({
  offsetX: 16 + 10,
  offsetY: 0,
  itemTypes: ["node"],
  trigger: "click",
  getContent(evt) {
    let header;
    if (evt.item) {
      const itemType = evt.item.getType();
      header = `${itemType.toUpperCase()} ContextMenu`;
    }
    return `
    <h3>${header}</h3>
    <ul>
      <li title='first' style="background:yellow">li 1</li>
      <li title='second' style="background:pink">li 2</li>
      <li title='third' style="background:green">li 3</li>
      <li title='fourth' style="background:orange">li 4</li>
    </ul>`;
  },
  handleMenuClick: (target, item) => {
    if (target.title === "first") {
      document.querySelector(".g6-component-contextmenu").style.visibility =
        "visible !important";
      document.querySelector(".g6-component-contextmenu").style.display =
        "block";
    }
  },
});
const container = document.getElementById("container");
const width = container.scrollWidth;
const height = container.scrollHeight || 500;
const graph = new G6.Graph({
  container: "container",
  width,
  height,
  fitView: false,
  defaultNode: {
    style: {
      fill: "#DEE9FF",
      stroke: "#5B8FF9",
    },
  },
  defaultEdge: {
    style: {
      stroke: "#b5b5b5",
    },
  },
  plugins: [contextMenu],
});
graph.data(data);
graph.render();
posted by Ourydy about 1 year ago

any progress about this bug?

posted by xiongchengqing about 1 year ago

This issue has been closed because it has been outdate for a long time. Please open a new issue if you still need help.

这个 issue 已经被关闭,因为 它已经过期很久了。 如果你仍然需要帮助,请创建一个新的 issue。

posted by github-actions[bot] 6 months ago

Fund this Issue

$0.00
Funded

Pull requests