Skip to content

Commit

Permalink
Merge pull request #2144 from hiyangguo/main
Browse files Browse the repository at this point in the history
fix: fixed an issue where Handle component onMouseDown event could not be bind
  • Loading branch information
moklick authored May 16, 2022
2 parents 415fc77 + a07f3dc commit aab0858
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
11 changes: 10 additions & 1 deletion example/src/CustomNode/ColorSelectorNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ const ColorSelectorNode: FC<NodeProps> = ({ data, isConnectable }) => {
Custom Color Picker Node: <strong>{data.color}</strong>
</div>
<input className="nodrag" type="color" onChange={data.onChange} defaultValue={data.color} />
<Handle type="source" position={Position.Right} id="a" style={sourceHandleStyleA} isConnectable={isConnectable} />
<Handle
type="source"
position={Position.Right}
id="a"
style={sourceHandleStyleA}
isConnectable={isConnectable}
onMouseDown={(e) => {
console.log('You trigger mousedown event', e);
}}
/>
<Handle type="source" position={Position.Right} id="b" style={sourceHandleStyleB} isConnectable={isConnectable} />
</>
);
Expand Down
4 changes: 2 additions & 2 deletions src/components/Edges/wrapEdge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -160,7 +160,7 @@ export default (EdgeComponent: ComponentType<EdgeProps>) => {
}
};

onMouseDown(
handleMouseDown(
event,
handleId,
nodeId,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Handle/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 5 additions & 3 deletions src/components/Handle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -35,6 +35,7 @@ const Handle = forwardRef<HTMLDivElement, HandleComponentProps>(
onConnect,
children,
className,
onMouseDown,
...rest
},
ref
Expand Down Expand Up @@ -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,
Expand All @@ -93,6 +94,7 @@ const Handle = forwardRef<HTMLDivElement, HandleComponentProps>(
onConnectEnd
);
}
onMouseDown?.(event);
},
[
handleId,
Expand Down

0 comments on commit aab0858

Please sign in to comment.