How to add a contextual menu to a node ? #190
-
I would add a right click contextual menu to a custom node. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
@clabnet I checked the component you linked and you just have to stop the propagation of the click - otherwise "vue-simple-context-menu" believes there was a click outside and immediately closes the context menu again So you can just do something like this onNodeClick(({ event }) => {
event.stopImmediatePropagation()
vueSimpleContextMenu.value.showMenu(event, { name: 'foo' })
}) You have to be aware though that this component will not scale by itself (when you scroll to zoom in and out, the context menu stays the same size) You can "fix" that by using the menu in your node component but that will cause the context menu to appear somewhere different than the node, simply because "vue-simple-context-menu" uses MouseEvent "pageX" and "pageY" values as left and top offsets You can assign a more fixed position to the context menu though by doing something like this, inside your custom node onNodeClick(({ event, node }) => {
if (node.id === props.id) {
event.stopImmediatePropagation()
vueSimpleContextMenu.value.showMenu({ pageX: props.dimensions.width - 75, pageY: props.dimensions.height + 5 }, { name: 'foo' })
}
}) import type { Dimensions, NodeProps } from '@braks/vue-flow'
interface CustomNodeProps extends NodeProps {
id: string
dimensions: Dimensions
} |
Beta Was this translation helpful? Give feedback.
-
I've used this approach to provide context menu to add additional nodes from an existing node, i.e, creating a new node, and connecting the new node to the current node. That works great. But, I'm running into a small problem. I've a node type called DecisionNode (a Diamond) which has 1 target handle, and 3 source handles on each of the vertices. When I use the UI to connect the nodes I could connect one for each of the source handles. But, when I do programmatically, after the first connection, all handles are becoming non connectable. On further observation I noticed that the classes "connectable connectionindicator" are missing from these handles. Is there a way I can set these classes programmatically?
|
Beta Was this translation helpful? Give feedback.
@clabnet I checked the component you linked and you just have to stop the propagation of the click - otherwise "vue-simple-context-menu" believes there was a click outside and immediately closes the context menu again
So you can just do something like this
You have to be aware though that this component will not scale by itself (when you scroll to zoom in and out, the context menu stays the same size)
You can "fix" that by using the menu in your node component but that will cause the context menu to appear somewhere different than the node, simply because "vue-s…