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 scrub lost unit on negative values (#1853)

Ivan Starkovaec1ca7db80a
diff --git a/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx b/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx
index 67967636db..5e0337a778 100644
--- a/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx
@@ -105,13 +105,22 @@ const useScrub = ({
// In case of negative values for some properties, we might end up with invalid value.
if (value.type === "invalid") {
- // Try return unitless
+ // Try 0 with same unit
+ if (isValidDeclaration(property, `0${unit}`)) {
+ return {
+ type: "unit",
+ unit,
+ value: 0,
+ } as const;
+ }
+
+ // Try unitless (in case of unit above was `number`
if (isValidDeclaration(property, "0")) {
- value = {
+ return {
type: "unit",
unit: "number",
value: 0,
- };
+ } as const;
}
}
}