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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
fix: don't round decimal unitless values for properties that accept them (#5673)
Oleg Isonen80150b75e1d1
diff --git a/apps/builder/app/builder/features/style-panel/shared/css-value-input/parse-intermediate-or-invalid-value.ts b/apps/builder/app/builder/features/style-panel/shared/css-value-input/parse-intermediate-or-invalid-value.tsindex 12c6311c90..6c4247bfed 100644--- a/apps/builder/app/builder/features/style-panel/shared/css-value-input/parse-intermediate-or-invalid-value.ts+++ b/apps/builder/app/builder/features/style-panel/shared/css-value-input/parse-intermediate-or-invalid-value.ts@@ -53,7 +53,12 @@ export const parseIntermediateOrInvalidValue = (if ("unit" in styleValue && styleValue.unit === "number") {const numericValue = Number(value);if (!Number.isNaN(numericValue) && !Number.isInteger(numericValue)) {- value = String(Math.round(numericValue));+ // Only round if the decimal value is not valid for this property+ // (e.g. z-index requires integers, but line-height accepts decimals)+ const decimalTest = parseCssValue(property, value);+ if (decimalTest.type === "invalid") {+ value = String(Math.round(numericValue));+ }}}diff --git a/apps/builder/app/builder/features/style-panel/shared/css-value-input/parse-intermediate-or-invalid-value.ts.test.ts b/apps/builder/app/builder/features/style-panel/shared/css-value-input/parse-intermediate-or-invalid-value.ts.test.tsindex 66683df9f8..a30fa5c064 100644--- a/apps/builder/app/builder/features/style-panel/shared/css-value-input/parse-intermediate-or-invalid-value.ts.test.ts+++ b/apps/builder/app/builder/features/style-panel/shared/css-value-input/parse-intermediate-or-invalid-value.ts.test.ts@@ -389,6 +389,48 @@ describe("Value ending with `-` should be considered unitless", () => {});});+ test("Decimal number intermediate for line-height is not rounded", () => {+ const result = parseIntermediateOrInvalidValue("line-height", {+ type: "intermediate",+ value: "1.5",+ unit: "number",+ });++ expect(result).toEqual({+ type: "unit",+ value: 1.5,+ unit: "number",+ });+ });++ test("Decimal number intermediate for z-index is rounded to integer", () => {+ const result = parseIntermediateOrInvalidValue("z-index", {+ type: "intermediate",+ value: "1.5",+ unit: "number",+ });++ expect(result).toEqual({+ type: "unit",+ value: 2,+ unit: "number",+ });+ });++ test("Decimal number intermediate for column-count is rounded to integer", () => {+ const result = parseIntermediateOrInvalidValue("column-count", {+ type: "intermediate",+ value: "2.7",+ unit: "number",+ });++ expect(result).toEqual({+ type: "unit",+ value: 3,+ unit: "number",+ });+ });+test("Unitless expression transformed to unitless", () => {const result = parseIntermediateOrInvalidValue("line-height", {type: "intermediate",