fix: fixed an issue where Handle component onMouseDown event could not be bind

This commit is contained in:
hiyangguo
2022-05-13 19:54:26 +08:00
parent 415fc77a3c
commit a07f3dc528
4 changed files with 18 additions and 7 deletions
+2 -2
View File
@@ -4,7 +4,7 @@ import shallow from 'zustand/shallow';
import { useStore, useStoreApi } from '../../store';
import { Edge, EdgeProps, WrapEdgeProps, ReactFlowState, Connection } from '../../types';
import { onMouseDown } from '../../components/Handle/handler';
import { handleMouseDown } from '../../components/Handle/handler';
import { EdgeAnchor } from './EdgeAnchor';
import { getMarkerId } from '../../utils/graph';
@@ -160,7 +160,7 @@ export default (EdgeComponent: ComponentType<EdgeProps>) => {
}
};
onMouseDown(
handleMouseDown(
event,
handleId,
nodeId,
+1 -1
View File
@@ -82,7 +82,7 @@ function resetRecentHandle(hoveredHandle: Element): void {
hoveredHandle?.classList.remove('react-flow__handle-connecting');
}
export function onMouseDown(
export function handleMouseDown(
event: ReactMouseEvent,
handleId: string | null,
nodeId: string,
+5 -3
View File
@@ -5,7 +5,7 @@ import shallow from 'zustand/shallow';
import { useStore, useStoreApi } from '../../store';
import NodeIdContext from '../../contexts/NodeIdContext';
import { HandleProps, Connection, ReactFlowState, Position } from '../../types';
import { checkElementBelowIsValid, onMouseDown } from './handler';
import { checkElementBelowIsValid, handleMouseDown } from './handler';
import { getHostForElement } from '../../utils';
import { addEdge } from '../../utils/graph';
@@ -35,6 +35,7 @@ const Handle = forwardRef<HTMLDivElement, HandleComponentProps>(
onConnect,
children,
className,
onMouseDown,
...rest
},
ref
@@ -75,9 +76,9 @@ const Handle = forwardRef<HTMLDivElement, HandleComponentProps>(
);
const onMouseDownHandler = useCallback(
(event: React.MouseEvent) => {
(event: React.MouseEvent<HTMLDivElement>) => {
if (event.button === 0) {
onMouseDown(
handleMouseDown(
event,
handleId,
nodeId,
@@ -93,6 +94,7 @@ const Handle = forwardRef<HTMLDivElement, HandleComponentProps>(
onConnectEnd
);
}
onMouseDown?.(event);
},
[
handleId,