Merge pull request #2894 from wbkd/fix/deselect-nodes-focus

fix(nodes): blur when node gets unselected
This commit is contained in:
Moritz Klack
2023-03-06 16:37:50 +01:00
committed by GitHub
4 changed files with 14 additions and 4 deletions

View File

@@ -0,0 +1,5 @@
---
'@reactflow/core': patch
---
fix(nodes): blur when node gets unselected

View File

@@ -1,4 +1,4 @@
import { MouseEvent } from 'react';
import { MouseEvent, RefObject } from 'react';
import { StoreApi } from 'zustand';
import { getDimensions } from '../../utils';
@@ -58,6 +58,7 @@ export function handleNodeClick({
id,
store,
unselect = false,
nodeRef,
}: {
id: string;
store: {
@@ -65,6 +66,7 @@ export function handleNodeClick({
setState: StoreApi<ReactFlowState>['setState'];
};
unselect?: boolean;
nodeRef?: RefObject<HTMLDivElement>;
}) {
const { addSelectedNodes, unselectNodesAndEdges, multiSelectionActive, nodeInternals } = store.getState();
const node = nodeInternals.get(id)!;
@@ -75,5 +77,7 @@ export function handleNodeClick({
addSelectedNodes([id]);
} else if (unselect || (node.selected && multiSelectionActive)) {
unselectNodesAndEdges({ nodes: [node] });
requestAnimationFrame(() => nodeRef?.current?.blur());
}
}

View File

@@ -74,6 +74,7 @@ export default (NodeComponent: ComponentType<NodeProps>) => {
handleNodeClick({
id,
store,
nodeRef,
});
}
@@ -90,13 +91,12 @@ export default (NodeComponent: ComponentType<NodeProps>) => {
if (elementSelectionKeys.includes(event.key) && isSelectable) {
const unselect = event.key === 'Escape';
if (unselect) {
nodeRef.current?.blur();
}
handleNodeClick({
id,
store,
unselect,
nodeRef,
});
} else if (
!disableKeyboardA11y &&

View File

@@ -153,6 +153,7 @@ function useDrag({
handleNodeClick({
id: nodeId,
store,
nodeRef: nodeRef as RefObject<HTMLDivElement>,
});
}