Merge pull request #5684 from ysds/fix/nodes-selection-drag-after-programmatic-selection

fix: ensure drag handlers update when nodes selection changes programmatically
This commit is contained in:
Moritz Klack
2026-02-18 21:13:47 +01:00
committed by GitHub
5 changed files with 72 additions and 16 deletions

View File

@@ -51,11 +51,14 @@ export function NodesSelection<NodeType extends Node>({
}
}, [disableKeyboardA11y]);
const shouldRender = !userSelectionActive && width !== null && height !== null;
useDrag({
nodeRef,
disabled: !shouldRender,
});
if (userSelectionActive || !width || !height) {
if (!shouldRender) {
return null;
}

View File

@@ -52,22 +52,23 @@ export function useDrag({
}, []);
useEffect(() => {
if (disabled) {
xyDrag.current?.destroy();
} else if (nodeRef.current) {
xyDrag.current?.update({
noDragClassName,
handleSelector,
domNode: nodeRef.current,
isSelectable,
nodeId,
nodeClickDistance,
});
return () => {
xyDrag.current?.destroy();
};
if (disabled || !nodeRef.current || !xyDrag.current) {
return;
}
}, [noDragClassName, handleSelector, disabled, isSelectable, nodeRef, nodeId]);
xyDrag.current.update({
noDragClassName,
handleSelector,
domNode: nodeRef.current,
isSelectable,
nodeId,
nodeClickDistance,
});
return () => {
xyDrag.current?.destroy();
};
}, [noDragClassName, handleSelector, disabled, isSelectable, nodeRef, nodeId, nodeClickDistance]);
return dragging;
}