Skip to content

Commit c30222e

Browse files
committed
docs: add handles section to guide
1 parent fe55415 commit c30222e

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

docs/src/.vitepress/config.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export default defineConfigWithTheme<DefaultTheme.Config>({
144144
{ text: 'Theming', link: '/guide/theming' },
145145
{ text: 'Nodes', link: '/guide/node' },
146146
{ text: 'Edges', link: '/guide/edge' },
147+
{ text: 'Handles', link: '/guide/handle' },
147148
{ text: 'Composables', link: '/guide/composables' },
148149
{ text: 'Controlled Flow', link: '/guide/controlled-flow' },
149150
],

docs/src/guide/handle.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: Handles
3+
---
4+
5+
# Introduction to Handles
6+
7+
Handles are the small circles that are usually placed on the borders of a node. They are used to connect nodes
8+
together by dragging a connection-line from one handle to another, resulting in a connection ([Edge](/guide/edge))
9+
between the nodes.
10+
11+
Handles are a crucial part of the VueFlow library, as they are the main interaction point for the user to create
12+
connections between nodes.
13+
14+
Without handles, it is basically impossible to create edges between nodes, as the `<Handle>` components are used
15+
to calculate the points for the edges.
16+
17+
## Handle Component
18+
19+
The `<Handle>` component is a simple component that is used to create a handle for a node. It is a wrapper around a
20+
`<div>` element that provides the necessary event handlers to create edges between nodes.
21+
22+
The `<Handle>` component is used in the `<Node>` component to create handles for the node.
23+
24+
## Multiple Handles
25+
26+
A node can have multiple handles, the number of handles is not limited and you can use as many handles as you need.
27+
When using multiple handles of the same type (`source` or `target`), each handle needs to have a unique id.
28+
29+
```vue
30+
<!-- each of these handles needs a unique id since we're using two `source` type handles -->
31+
<Handle id="a" type="source" :position="Position.Right" />
32+
<Handle id="b" type="source" :position="Position.Right" />
33+
```
34+
35+
The `id` prop is used to identify the handle when creating edges between nodes. If no `id` is provided, the first handle
36+
of the necessary type will be used.
37+
38+
```ts
39+
const { onConnect } = useVueFlow()
40+
41+
onConnect(({ source, target, sourceHandle, targetHandle }) => {
42+
console.log('source', source)
43+
console.log('target', target)
44+
// these are the handle ids of the source and target node
45+
// if no id is specified these will be `null`, meaning the first handle of the necessary type will be used
46+
console.log('sourceHandle', sourceHandle)
47+
console.log('targetHandle', targetHandle)
48+
})
49+
```
50+
51+
## Hide Handles
52+
53+
In some cases you might not want to display a handle at all. You can hide a handle by setting `opacity: 0` as the styles for that handle.
54+
55+
You cannot hide a handle by removing it from the DOM (for example using `v-if` or `v-show`) as that would break the calculations for the edges.
56+
57+
```vue
58+
<Handle type="source" :position="Position.Right" style="opacity: 0" />
59+
```

0 commit comments

Comments
 (0)