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: preserve shadow labels when hiding repeated items (#5663)

Shrek6359d27f6f10
diff --git a/apps/builder/app/builder/features/style-panel/sections/box-shadows/box-shadows.tsx b/apps/builder/app/builder/features/style-panel/sections/box-shadows/box-shadows.tsx
index 2ed96470b4..a9e826eb55 100644
--- a/apps/builder/app/builder/features/style-panel/sections/box-shadows/box-shadows.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/box-shadows/box-shadows.tsx
@@ -24,7 +24,11 @@ const initialBoxShadow = "0px 2px 5px 0px rgba(0, 0, 0, 0.2)";
const getItemProps = (layer: StyleValue, computedLayer?: StyleValue) => {
const shadowValue =
- computedLayer?.type === "shadow" ? computedLayer : undefined;
+ layer.type === "shadow"
+ ? layer
+ : computedLayer?.type === "shadow"
+ ? computedLayer
+ : undefined;
const labels = [];
if (shadowValue?.position === "inset") {
labels.push("Inner:");
@@ -39,7 +43,7 @@ const getItemProps = (layer: StyleValue, computedLayer?: StyleValue) => {
labels.push(toValue(shadowValue.blur));
labels.push(toValue(shadowValue.spread));
} else {
- labels.push(toValue(shadowValue));
+ labels.push(toValue(layer));
}
const color = shadowValue?.color ? toValue(shadowValue.color) : undefined;
return { label: labels.join(" "), color };
diff --git a/apps/builder/app/builder/features/style-panel/sections/text-shadows/text-shadows.tsx b/apps/builder/app/builder/features/style-panel/sections/text-shadows/text-shadows.tsx
index 3ffaeebf7d..7be1c784aa 100644
--- a/apps/builder/app/builder/features/style-panel/sections/text-shadows/text-shadows.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/text-shadows/text-shadows.tsx
@@ -24,7 +24,11 @@ const initialTextShadow = "0px 2px 5px rgba(0, 0, 0, 0.2)";
const getItemProps = (layer: StyleValue, computedLayer?: StyleValue) => {
const shadowValue =
- computedLayer?.type === "shadow" ? computedLayer : undefined;
+ layer.type === "shadow"
+ ? layer
+ : computedLayer?.type === "shadow"
+ ? computedLayer
+ : undefined;
const labels = [];
if (layer.type === "var") {
labels.push(`--${layer.value}`);
@@ -33,7 +37,7 @@ const getItemProps = (layer: StyleValue, computedLayer?: StyleValue) => {
labels.push(toValue(shadowValue.offsetY));
labels.push(toValue(shadowValue.blur));
} else {
- labels.push(toValue(shadowValue));
+ labels.push(toValue(layer));
}
const color = shadowValue?.color ? toValue(shadowValue.color) : undefined;
return { label: labels.join(" "), color };
diff --git a/apps/builder/app/builder/features/style-panel/shared/repeated-style.test.ts b/apps/builder/app/builder/features/style-panel/shared/repeated-style.test.ts
index 358f880776..a6aea87377 100644
--- a/apps/builder/app/builder/features/style-panel/shared/repeated-style.test.ts
+++ b/apps/builder/app/builder/features/style-panel/shared/repeated-style.test.ts
@@ -10,6 +10,7 @@ import {
addRepeatedStyleItem,
deleteRepeatedStyleItem,
editRepeatedStyleItem,
+ getComputedRepeatedItem,
getRepeatedStyleItem,
setRepeatedStyleItem,
swapRepeatedStyleItems,
@@ -477,6 +478,53 @@ describe("toggle repeated item", () => {
// color should not switch to 1s when hide first layer
expect(toValue($transitionDuration.get().cascadedValue)).toEqual("2s, 1s");
});
+
+ test("preserves computed layer mapping for hidden box shadows", () => {
+ const $boxShadow = createComputedStyleDeclStore("box-shadow");
+ setRawProperty(
+ "box-shadow",
+ "1px 2px 3px red, inset 4px 5px 6px blue, 7px 8px 9px green"
+ );
+
+ toggleRepeatedStyleItem([$boxShadow.get()], 0);
+
+ expect(getComputedRepeatedItem($boxShadow.get(), 0)).toMatchObject({
+ type: "shadow",
+ hidden: true,
+ position: "outset",
+ });
+ expect(getComputedRepeatedItem($boxShadow.get(), 1)).toMatchObject({
+ type: "shadow",
+ position: "inset",
+ });
+ expect(getComputedRepeatedItem($boxShadow.get(), 2)).toMatchObject({
+ type: "shadow",
+ position: "outset",
+ offsetX: { type: "unit", unit: "px", value: 7 },
+ offsetY: { type: "unit", unit: "px", value: 8 },
+ blur: { type: "unit", unit: "px", value: 9 },
+ });
+ });
+
+ test("preserves computed layer mapping for hidden text shadows", () => {
+ const $textShadow = createComputedStyleDeclStore("text-shadow");
+ setRawProperty("text-shadow", "1px 2px 3px red, 4px 5px 6px blue");
+
+ toggleRepeatedStyleItem([$textShadow.get()], 0);
+
+ expect(getComputedRepeatedItem($textShadow.get(), 0)).toMatchObject({
+ type: "shadow",
+ hidden: true,
+ position: "outset",
+ });
+ expect(getComputedRepeatedItem($textShadow.get(), 1)).toMatchObject({
+ type: "shadow",
+ position: "outset",
+ offsetX: { type: "unit", unit: "px", value: 4 },
+ offsetY: { type: "unit", unit: "px", value: 5 },
+ blur: { type: "unit", unit: "px", value: 6 },
+ });
+ });
});
describe("swap repeated items", () => {
diff --git a/apps/builder/app/builder/features/style-panel/shared/repeated-style.tsx b/apps/builder/app/builder/features/style-panel/shared/repeated-style.tsx
index 608c0fee84..d5bcd916d6 100644
--- a/apps/builder/app/builder/features/style-panel/shared/repeated-style.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/repeated-style.tsx
@@ -42,12 +42,32 @@ export const getComputedRepeatedItem = (
) => {
const value = reparseComputedValue(styleDecl);
const items = isRepeatedValue(value) ? value.value : [];
- if (
- isRepeatedValue(styleDecl.cascadedValue) &&
- styleDecl.cascadedValue.value.length !== items.length
- ) {
+ if (items.length === 0) {
return;
}
+ if (isRepeatedValue(styleDecl.cascadedValue)) {
+ const cascadedItems = styleDecl.cascadedValue.value;
+ if (cascadedItems.length !== items.length) {
+ const item = cascadedItems[index];
+ // Hidden repeated items are omitted from serialized computed CSS,
+ // so remap the requested cascaded index onto the remaining visible items.
+ const visibleItems = cascadedItems.filter((item) => item.hidden !== true);
+ if (visibleItems.length !== items.length) {
+ return;
+ }
+ if (
+ item?.hidden === true &&
+ item.type !== "var" &&
+ item.type !== "unparsed"
+ ) {
+ return item;
+ }
+ const hiddenItems = cascadedItems
+ .slice(0, index)
+ .filter((item) => item.hidden === true).length;
+ return items[index - hiddenItems];
+ }
+ }
return items[index % items.length];
};
diff --git a/apps/builder/docs/test-cases.md b/apps/builder/docs/test-cases.md
index 9a4b5ba837..3bad852fb3 100644
--- a/apps/builder/docs/test-cases.md
+++ b/apps/builder/docs/test-cases.md
@@ -41,6 +41,15 @@
- Change any style
- See if it is applied
+1. Repeated shadow labels
+
+ - Select an instance
+ - Add at least 3 `box-shadow` layers in the style panel
+ - Hide the first layer
+ - Check that all `box-shadow` rows keep their full labels and only the hidden row is visually muted
+ - Repeat the same flow with at least 3 `text-shadow` layers
+ - Check that all `text-shadow` rows keep their full labels after hiding one layer
+
1. Content editable components
- Add any contenteditable component (heading, paragraph, text ...)