With the dragHandle selector attribute of a node you can specify which area should be used to drag it.
Drag Handle Source Code
DragHandleNode.tsx
import React, { memo, FC } from 'react';
import {
Handle,
Position,
NodeProps,
Connection,
Edge,
} from 'react-flow-renderer';
const onConnect = (params: Connection | Edge) =>
console.log('handle onConnect', params);
const labelStyle = {
display: 'flex',
alignItems: 'center',
};
const dragHandleStyle = {
display: 'inline-block',
width: 25,
height: 25,
backgroundColor: 'teal',
marginLeft: 5,
borderRadius: '50%',
};
const ColorSelectorNode: FC<NodeProps> = () => {
return (
<>
<Handle type="target" position={Position.Left} onConnect={onConnect} />
<div style={labelStyle}>
Only draggable here →{' '}
<span className="custom-drag-handle" style={dragHandleStyle} />
</div>
<Handle type="source" position={Position.Right} />
</>
);
};
export default memo(ColorSelectorNode);
index.tsx
import React from 'react';
import ReactFlow from 'react-flow-renderer';
import DragHandleNode from './DragHandleNode';
const nodeTypes = {
dragHandleNode: DragHandleNode,
};
const elements = [
{
id: '2',
type: 'dragHandleNode',
dragHandle: '.custom-drag-handle',
style: { border: '1px solid #ddd', padding: '20px 40px' },
position: { x: 200, y: 200 },
},
];
const DragHandleFlow = () => (
<ReactFlow elements={elements} nodeTypes={nodeTypes} />
);
export default DragHandleFlow;