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.

experimental: set collisionPadding for background panel to reduce panel jumps. (#3533)

Jaya Krishna Namburuee150a5d0a02
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/backgrounds.tsx b/apps/builder/app/builder/features/style-panel/sections/backgrounds/backgrounds.tsx
index aa27b9a5b8..13e99ad3c7 100644
--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/backgrounds.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/backgrounds.tsx
@@ -88,6 +88,12 @@ const Layer = (props: {
return (
<FloatingPanel
title="Background"
+ // Background Panel is big, and the size differs when the tabs are changed.
+ // This results in the panel moving around when the tabs are changed.
+ // And sometimes, the tab moves away from the cursor, when the content change happens on the top.
+ // This is a workaround to prevent the panel from moving around too much when the tabs are changed from the popover trigger.
+ align="center"
+ collisionPadding={{ bottom: 200, top: 200 }}
content={
<BackgroundContent
currentStyle={props.layerStyle}
diff --git a/apps/builder/app/builder/shared/floating-panel.tsx b/apps/builder/app/builder/shared/floating-panel.tsx
index edb557a319..837b9da209 100644
--- a/apps/builder/app/builder/shared/floating-panel.tsx
+++ b/apps/builder/app/builder/shared/floating-panel.tsx
@@ -92,6 +92,11 @@ type FloatingPanelProps = {
children: JSX.Element;
open?: boolean;
onOpenChange?: (isOpen: boolean) => void;
+ // collisionPadding is the distance in pixels from the boundary edges where collision detection should occur.
+ collisionPadding?:
+ | number
+ | Partial<Record<"top" | "right" | "bottom" | "left", number>>;
+ align?: "start" | "center" | "end";
};
const contentStyle = css({
@@ -103,7 +108,9 @@ export const FloatingPanel = ({
content,
children,
open,
+ align,
onOpenChange,
+ collisionPadding,
}: FloatingPanelProps) => {
const { isOpen, handleOpenChange, triggerRef, sideOffset } = useLogic(
open,
@@ -118,8 +125,9 @@ export const FloatingPanel = ({
<FloatingPanelPopoverContent
sideOffset={sideOffset}
side="left"
- align="start"
+ align={align ?? "start"}
className={contentStyle()}
+ collisionPadding={collisionPadding}
>
{content}
<FloatingPanelPopoverTitle>{title}</FloatingPanelPopoverTitle>