From 8cd3dc3c8dae27d566bce87afe8a6c16e0b7e7ff Mon Sep 17 00:00:00 2001 From: Ivan Starkov Date: Thu, 12 Dec 2024 18:33:20 +0700 Subject: [PATCH] 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 --- .../src/components/primitives/dnd/use-drag.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/design-system/src/components/primitives/dnd/use-drag.ts b/packages/design-system/src/components/primitives/dnd/use-drag.ts index 57c603df27e4..b469a781dfb4 100644 --- a/packages/design-system/src/components/primitives/dnd/use-drag.ts +++ b/packages/design-system/src/components/primitives/dnd/use-drag.ts @@ -190,6 +190,17 @@ export const useDrag = ( }; }, []); + useEffect( + () => () => { + // A component can be disposed of during dragging + // (e.g., by pressing Escape or closing the components panel while dragging). + if (state.current.status === "dragging") { + end(true); + } + }, + [end] + ); + useEffect(() => { if (rootElement !== null) { rootElement.addEventListener("pointerdown", handlePointerDown);