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 editing of background gradient resetted other properties of the curent layer (#1598)

Ivan Starkov812cbaab14c3
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-layers.test.ts b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-layers.test.ts
index dce59690a5..781852421b 100644
--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-layers.test.ts
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-layers.test.ts
@@ -228,11 +228,37 @@ describe("setLayerProperty", () => {
],
},
};
+
+ const cascadedPosition: NonNullable<
+ StyleInfo["backgroundPosition"]
+ >["cascaded"] = {
+ breakpointId: "mobile",
+ value: {
+ type: "layers",
+ value: [
+ {
+ type: "unit",
+ value: 10,
+ unit: "%",
+ },
+ {
+ type: "unit",
+ value: 50,
+ unit: "%",
+ },
+ ],
+ },
+ };
+
const styleInfo: StyleInfo = {
backgroundImage: {
cascaded,
value: cascaded.value,
},
+ backgroundPosition: {
+ cascaded: cascadedPosition,
+ value: cascadedPosition.value,
+ },
};
let published = false;
@@ -289,6 +315,25 @@ describe("setLayerProperty", () => {
}
`);
+ // We should not reset existing properties to default values
+ expect(styleInfo.backgroundPosition?.value).toMatchInlineSnapshot(`
+ {
+ "type": "layers",
+ "value": [
+ {
+ "type": "unit",
+ "unit": "%",
+ "value": 10,
+ },
+ {
+ "type": "unit",
+ "unit": "%",
+ "value": 50,
+ },
+ ],
+ }
+ `);
+
setProperty("backgroundImage")({
type: "layers",
value: [
@@ -322,6 +367,29 @@ describe("setLayerProperty", () => {
],
}
`);
+
+ expect(styleInfo.backgroundPosition?.value).toMatchInlineSnapshot(`
+ {
+ "type": "layers",
+ "value": [
+ {
+ "type": "unit",
+ "unit": "%",
+ "value": 10,
+ },
+ {
+ "type": "unit",
+ "unit": "%",
+ "value": 50,
+ },
+ {
+ "type": "unit",
+ "unit": "%",
+ "value": 0,
+ },
+ ],
+ }
+ `);
});
});
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-layers.ts b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-layers.ts
index 34f56ebce6..6022b7d25b 100644
--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-layers.ts
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-layers.ts
@@ -271,9 +271,12 @@ export const setLayerProperty =
const insertItems =
property === propertyName
? newValue.value
- : Array.from(
- Array(newValue.value.length),
- () => layeredBackgroundPropsDefaults[property]
+ : Array.from(Array(newValue.value.length), (_, index) =>
+ // Do not override existing values with defaults for layerNum layer
+ index === 0
+ ? newPropertyStyle.value[layerNum] ??
+ layeredBackgroundPropsDefaults[property]
+ : layeredBackgroundPropsDefaults[property]
);
newPropertyStyle.value.splice(layerNum, 1, ...insertItems);