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.

use state for temp value, support floating numbers

Oleg Isonen854516f7c3ff
diff --git a/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx b/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx
index 7600895f23..3c9afeb625 100644
--- a/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx
+++ b/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx
@@ -1,7 +1,8 @@
import { CssValueInput } from "~/designer/features/style-panel/shared/css-value-input/css-value-input";
import { getFinalValue } from "../../shared/get-final-value";
import { ControlProps } from "../../style-sections";
-import { toValue } from "@webstudio-is/react-sdk";
+import { type StyleValue, toValue } from "@webstudio-is/react-sdk";
+import { useState } from "react";
export const TextControl = ({
currentStyle,
@@ -17,18 +18,22 @@ export const TextControl = ({
const setValue = setProperty(styleConfig.property);
+ const [tempValue, setTempValue] = useState<StyleValue>();
+
return (
<CssValueInput
property={styleConfig.property}
- value={value}
+ value={tempValue ?? value}
keywords={styleConfig.items.map((item) => ({
type: "keyword",
value: item.name,
}))}
onChange={(styleValue) => {
+ setTempValue(styleValue);
setValue(toValue(styleValue), { isEphemeral: true });
}}
onChangeComplete={(styleValue) => {
+ setTempValue(undefined);
setValue(toValue(styleValue));
}}
/>
diff --git a/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx b/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx
index 3d733f4caa..8c302e33b3 100644
--- a/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx
+++ b/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx
@@ -47,7 +47,7 @@ const useOnChange = (
if (input === valueRef.current.value) return;
// We want to switch to unit mode if entire input is a number.
- if (/^\d+$/.test(input)) {
+ if (input.trim().length !== 0 && isNaN(Number(input)) === false) {
onChange?.({
type: "unit",
// Use previously known unit or fallback to px.