Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

fix: Pressing Escape during component dragging makes the canvas unselectable. (#4571)

Ivan Starkov8cd3dc3c8dae
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 57c603df27..b469a781df 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 = <DragItemData>(
};
}, []);
+ 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);