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 dragging components onto canvas

Oleg Isonen64063bd50a27
diff --git a/app/designer/sidebar-left/panels/components.tsx b/app/designer/sidebar-left/panels/components.tsx
index ee01abccb7..8f4ec0eb35 100644
--- a/app/designer/sidebar-left/panels/components.tsx
+++ b/app/designer/sidebar-left/panels/components.tsx
@@ -3,6 +3,7 @@ import {
useRef,
MutableRefObject,
type MouseEventHandler,
+ useCallback,
} from "react";
import { useDrag } from "react-dnd";
import { type Instance } from "@webstudio-is/sdk";
@@ -86,6 +87,17 @@ export const TabContent = ({
const components = (
Object.keys(primitives) as Array<Instance["component"]>
).filter((component) => primitives[component].isInlineOnly === false);
+
+ const handleDragChange = useCallback(
+ (isDragging: boolean) => {
+ onDragChange(isDragging);
+ publish<"dragStartComponent" | "dragEndComponent">({
+ type: isDragging === true ? "dragStartComponent" : "dragEndComponent",
+ });
+ },
+ [onDragChange, publish]
+ );
+
return (
<Flex gap="1" wrap="wrap" css={{ padding: "$1" }}>
{components.map((component: Instance["component"]) => (
@@ -101,13 +113,7 @@ export const TabContent = ({
payload: { component },
});
}}
- onDragChange={(isDragging: boolean) => {
- onDragChange(isDragging);
- publish<"dragStartComponent" | "dragEndComponent">({
- type:
- isDragging === true ? "dragStartComponent" : "dragEndComponent",
- });
- }}
+ onDragChange={handleDragChange}
/>
))}
<CustomDragLayer
diff --git a/app/designer/sidebar-left/sidebar-left.tsx b/app/designer/sidebar-left/sidebar-left.tsx
index d738e8cf5d..486ca63360 100644
--- a/app/designer/sidebar-left/sidebar-left.tsx
+++ b/app/designer/sidebar-left/sidebar-left.tsx
@@ -1,4 +1,4 @@
-import { useState, MutableRefObject } from "react";
+import { useState, MutableRefObject, useCallback } from "react";
import {
Box,
SidebarTabs,
@@ -45,6 +45,17 @@ export const SidebarLeft = ({
setActiveTab("none");
});
+ const handleDragChange = useCallback(
+ (isDragging: boolean) => {
+ // After dragging is done, container is going to become visible
+ // and we need to close it for good.
+ if (isDragging === false) setActiveTab("none");
+ setIsDragging(isDragging);
+ onDragChange(isDragging);
+ },
+ [onDragChange]
+ );
+
return (
<Box css={{ position: "relative" }}>
<SidebarTabs activationMode="manual" value={activeTab}>
@@ -77,13 +88,7 @@ export const SidebarLeft = ({
publish={publish}
iframeRef={iframeRef}
onSetActiveTab={setActiveTab}
- onDragChange={(isDragging: boolean) => {
- // After dragging is done, container is going to become visible
- // and we need to close it for good.
- if (isDragging === false) setActiveTab("none");
- setIsDragging(isDragging);
- onDragChange(isDragging);
- }}
+ onDragChange={handleDragChange}
/>
</SidebarTabsContent>
</SidebarTabs>