<Handle />
The <Handle /> component is used in your custom nodes
to define connection points.
<!-- CustomNode.vue -->
<script setup lang="ts">
import { Handle, Position, type NodeProps } from '@xyflow/vue';
defineProps<NodeProps>();
</script>
<template>
<div>{{ data.label }}</div>
<Handle type="target" :position="Position.Left" />
<Handle type="source" :position="Position.Right" />
</template>Props
The type for props of <Handle /> component is exported as HandleProps.
| Name | Type | Default |
|---|---|---|
id | stringId of the handle. | |
type | 'source' | 'target'Type of the handle. | "source" |
position | PositionThe position of the handle relative to the node. In a horizontal flow source handles are
typically | Position.Top |
isValidConnection | IsValidConnectionCalled when a connection is dragged to this handle. You can use this callback to perform some
custom validation logic based on the connection target and source, for example. Where possible,
we recommend you move this logic to the | |
isConnectable | HandleConnectableShould you be able to connect to/from this handle. | true |
isConnectableStart | booleanDictates whether a connection can start from this handle. | true |
isConnectableEnd | booleanDictates whether a connection can end on this handle. | true |
Examples
Custom handle with validation
You can build your own handle by wrapping <Handle />. This example only allows a
connection when the connection source matches a given id.
<!-- CustomHandle.vue -->
<script setup lang="ts">
import { Handle, type HandleProps, type Connection } from '@xyflow/vue';
const { source, ...rest } = defineProps<HandleProps & { source: string }>();
function isValidConnection(connection: Connection) {
return connection.source === source;
}
</script>
<template>
<Handle type="target" :is-valid-connection="isValidConnection" v-bind="rest" />
</template>Styling handles while connecting
A handle receives the class connecting while the connection line is above it, and
valid when the connection is valid — use these to color handles during a
connection. See the validation example.
Multiple handles
If you need more than one source or target handle, give each handle an id. Edges
then target a specific handle via sourceHandle / targetHandle — e.g. a node
node-1 with a handle handle-1 is reached by an edge with
source: 'node-1', sourceHandle: 'handle-1'.
Dynamic handles
If you programmatically change the position or number of handles in a custom node,
call updateNodeInternals (from useVueFlow())
for that node so Vue Flow re-measures its handles.