Skip to content

Commit 8cd3dc3

Browse files
authored
fix: Pressing Escape during component dragging makes the canvas unselectable. (#4571)
## Description 1. What is this PR about (link the issue and add a short description) ## Steps for reproduction 1. click button 2. expect xyz ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 0000) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
1 parent 5de42b2 commit 8cd3dc3

File tree

1 file changed

+11
-0
lines changed
  • packages/design-system/src/components/primitives/dnd

1 file changed

+11
-0
lines changed

packages/design-system/src/components/primitives/dnd/use-drag.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,17 @@ export const useDrag = <DragItemData>(
190190
};
191191
}, []);
192192

193+
useEffect(
194+
() => () => {
195+
// A component can be disposed of during dragging
196+
// (e.g., by pressing Escape or closing the components panel while dragging).
197+
if (state.current.status === "dragging") {
198+
end(true);
199+
}
200+
},
201+
[end]
202+
);
203+
193204
useEffect(() => {
194205
if (rootElement !== null) {
195206
rootElement.addEventListener("pointerdown", handlePointerDown);

0 commit comments

Comments
 (0)