fix(no-drag): handle noDragClassName correctly closes #2172

This commit is contained in:
moklick
2022-05-26 17:54:38 +02:00
parent 1e1ebff3b7
commit 101f5d25d0
2 changed files with 9 additions and 13 deletions
+8 -12
View File
@@ -5,13 +5,7 @@ import { select } from 'd3-selection';
import { useStoreApi } from '../../store';
import { pointToRendererPoint } from '../../utils/graph';
import { NodeDragItem, NodeDragHandler, XYPosition } from '../../types';
import {
getDragItems,
getEventHandlerParams,
getParentNodePosition,
selectorExistsTargetToNode,
updatePosition,
} from './utils';
import { getDragItems, getEventHandlerParams, getParentNodePosition, hasSelector, updatePosition } from './utils';
import { handleNodeClick } from '../../components/Nodes/utils';
export type UseDragEvent = D3DragEvent<HTMLDivElement, null, SubjectPosition>;
@@ -136,11 +130,13 @@ function useDrag({
})
.filter((event: MouseEvent) => {
const target = event.target as HTMLDivElement;
const filter =
!event.ctrlKey && !event.button && (!noDragClassName || !target.classList?.contains?.(noDragClassName));
return handleSelector
? selectorExistsTargetToNode(target as HTMLDivElement, handleSelector, nodeRef) && filter
: filter;
const isDraggable =
!event.ctrlKey &&
!event.button &&
(!noDragClassName || !hasSelector(target, `.${noDragClassName}`, nodeRef)) &&
(!handleSelector || hasSelector(target, handleSelector, nodeRef));
return isDraggable;
});
selection.call(dragHandler);
+1 -1
View File
@@ -31,7 +31,7 @@ export function getParentNodePosition(nodeInternals: NodeInternals, nodeId?: str
};
}
export function selectorExistsTargetToNode(target: Element, selector: string, nodeRef: RefObject<Element>): boolean {
export function hasSelector(target: Element, selector: string, nodeRef: RefObject<Element>): boolean {
let current = target;
do {