refactor(edgetext): catch pointer events closes #1121
This commit is contained in:
@@ -192,7 +192,7 @@ const OverviewFlow = () => {
|
|||||||
>
|
>
|
||||||
<MiniMap nodeStrokeColor={nodeStrokeColor} nodeColor={nodeColor} nodeBorderRadius={2} />
|
<MiniMap nodeStrokeColor={nodeStrokeColor} nodeColor={nodeColor} nodeBorderRadius={2} />
|
||||||
<Controls />
|
<Controls />
|
||||||
<Background color="#aaa" gap={20} size={1} />
|
<Background color="#aaa" gap={20} />
|
||||||
</ReactFlow>
|
</ReactFlow>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import React, { memo, useRef, useState, useEffect, FC } from 'react';
|
import React, { memo, useRef, useState, useEffect, FC } from 'react';
|
||||||
|
import cc from 'classcat';
|
||||||
|
|
||||||
import { EdgeTextProps, Rect } from '../../types';
|
import { EdgeTextProps, Rect } from '../../types';
|
||||||
|
|
||||||
@@ -12,10 +13,12 @@ const EdgeText: FC<EdgeTextProps> = ({
|
|||||||
labelBgPadding = [2, 4],
|
labelBgPadding = [2, 4],
|
||||||
labelBgBorderRadius = 2,
|
labelBgBorderRadius = 2,
|
||||||
children,
|
children,
|
||||||
|
className,
|
||||||
...rest
|
...rest
|
||||||
}) => {
|
}) => {
|
||||||
const edgeRef = useRef<SVGTextElement>(null);
|
const edgeRef = useRef<SVGTextElement>(null);
|
||||||
const [edgeTextBbox, setEdgeTextBbox] = useState<Rect>({ x: 0, y: 0, width: 0, height: 0 });
|
const [edgeTextBbox, setEdgeTextBbox] = useState<Rect>({ x: 0, y: 0, width: 0, height: 0 });
|
||||||
|
const edgeTextClasses = cc(['react-flow__edge-textwrapper', className]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (edgeRef.current) {
|
if (edgeRef.current) {
|
||||||
@@ -35,7 +38,11 @@ const EdgeText: FC<EdgeTextProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<g transform={`translate(${x - edgeTextBbox.width / 2} ${y - edgeTextBbox.height / 2})`} {...rest}>
|
<g
|
||||||
|
transform={`translate(${x - edgeTextBbox.width / 2} ${y - edgeTextBbox.height / 2})`}
|
||||||
|
className={edgeTextClasses}
|
||||||
|
{...rest}
|
||||||
|
>
|
||||||
{labelShowBg && (
|
{labelShowBg && (
|
||||||
<rect
|
<rect
|
||||||
width={edgeTextBbox.width + 2 * labelBgPadding[0]}
|
width={edgeTextBbox.width + 2 * labelBgPadding[0]}
|
||||||
|
|||||||
@@ -59,6 +59,10 @@
|
|||||||
fill: none;
|
fill: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.react-flow__edge-textwrapper {
|
||||||
|
pointer-events: all;
|
||||||
|
}
|
||||||
|
|
||||||
.react-flow__edge-text {
|
.react-flow__edge-text {
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
|
|||||||
Reference in New Issue
Block a user