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.

feat: show unresolved inherited values in style panel (#4990)

Bogdan Chadkinfcb4e25a9eea
diff --git a/apps/builder/app/shared/style-object-model.test.tsx b/apps/builder/app/shared/style-object-model.test.tsx
index 35ed180fc6..d9fb2d0f63 100644
--- a/apps/builder/app/shared/style-object-model.test.tsx
+++ b/apps/builder/app/shared/style-object-model.test.tsx
@@ -954,11 +954,11 @@ test("access cascaded value without resolving", () => {
).toEqual({ type: "keyword", value: "initial" });
});
-test("fallback cascaded value to inherited computed value", () => {
+test("fallback cascaded value to initial value", () => {
const model = createModel({
css: `
body {
- border-top-color: currentcolor;
+ width: 10px;
}
`,
jsx: (
@@ -971,9 +971,32 @@ test("fallback cascaded value to inherited computed value", () => {
getComputedStyleDecl({
model,
instanceSelector: ["box", "body"],
- property: "border-top-color",
+ property: "width",
+ }).cascadedValue
+ ).toEqual({ type: "keyword", value: "auto" });
+});
+
+test("fallback cascaded value to inherited unresolved value", () => {
+ const model = createModel({
+ css: `
+ body {
+ --color: red;
+ color: var(--color);
+ }
+ `,
+ jsx: (
+ <$.Body ws:id="body" class="body">
+ <$.Box ws:id="box" class="box"></$.Box>
+ </$.Body>
+ ),
+ });
+ expect(
+ getComputedStyleDecl({
+ model,
+ instanceSelector: ["box", "body"],
+ property: "color",
}).cascadedValue
- ).toEqual({ type: "keyword", value: "currentColor" });
+ ).toEqual({ type: "var", value: "color" });
});
test("work with unknown or invalid properties", () => {
diff --git a/apps/builder/app/shared/style-object-model.ts b/apps/builder/app/shared/style-object-model.ts
index 47ff0e512e..a3d9f7cf79 100644
--- a/apps/builder/app/shared/style-object-model.ts
+++ b/apps/builder/app/shared/style-object-model.ts
@@ -342,6 +342,7 @@ export const getComputedStyleDecl = ({
state,
property,
});
+ const inheritedCascadedValue = cascadedValue;
cascadedValue = cascaded?.value;
source = cascaded?.source ?? { name: "default" };
@@ -372,6 +373,7 @@ export const getComputedStyleDecl = ({
// defaulting https://drafts.csswg.org/css-cascade-5/#defaulting
else if (inherited) {
specifiedValue = inheritedValue;
+ cascadedValue = inheritedCascadedValue;
source = inheritedSource;
} else {
specifiedValue = initialValue;
@@ -436,8 +438,8 @@ export const getComputedStyleDecl = ({
usedValue = currentColor.usedValue;
}
- // fallback to inherited value
- cascadedValue ??= computedValue;
+ // fallback to initial value
+ cascadedValue ??= initialValue;
return { property, source, cascadedValue, computedValue, usedValue };
};