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 valid css-value false positives, refactor input active state, fix panel border regression from merge

Sultan10002a0f59b5
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 d576837bda..77f45a8f8a 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
@@ -22,6 +22,7 @@ import {
type KeyboardEvent,
useEffect,
useRef,
+ useState,
} from "react";
import { useUnitSelect } from "./unit-select";
@@ -83,8 +84,9 @@ const useScrub = ({
value: StyleValue;
onChange: (value: StyleValue) => void;
onChangeComplete: (value: StyleValue) => void;
-}) => {
+}): [React.MutableRefObject<HTMLInputElement | null>, boolean] => {
const inputRef = useRef<HTMLInputElement | null>(null);
+ const [inputActiveState, setInputActiveState] = useState(false);
const onChangeRef = useRef(onChange);
const onChangeCompleteRef = useRef(onChangeComplete);
const valueRef = useRef(value);
@@ -110,8 +112,8 @@ const useScrub = ({
unit,
value: event.value,
});
+ setInputActiveState(true);
inputRef.current?.blur();
- inputRef.current?.parentElement?.setAttribute("data-state", "focus");
},
onValueChange(event) {
onChangeCompleteRef.current({
@@ -119,16 +121,16 @@ const useScrub = ({
unit,
value: event.value,
});
+ setInputActiveState(false);
inputRef.current?.focus();
inputRef.current?.select();
- inputRef.current?.parentElement?.removeAttribute("data-state");
},
});
return scrub.disconnectedCallback;
}, [type, unit]);
- return inputRef;
+ return [inputRef, inputActiveState];
};
const useHandleKeyDown =
@@ -247,7 +249,7 @@ export const CssValueInput = ({
},
});
- const inputRef = useScrub({
+ const [inputRef, inputActiveState] = useScrub({
value,
onChange,
onChangeComplete,
@@ -294,7 +296,13 @@ export const CssValueInput = ({
onKeyDown={handleKeyDown}
inputRef={inputRef}
name={property}
- state={value.type === "invalid" ? "invalid" : undefined}
+ state={
+ value.type === "invalid"
+ ? "invalid"
+ : inputActiveState
+ ? "active"
+ : undefined
+ }
suffix={suffix}
css={{ cursor: "default" }}
/>
diff --git a/apps/designer/app/designer/features/style-panel/shared/get-final-value.ts b/apps/designer/app/designer/features/style-panel/shared/get-final-value.ts
index 9a6cabd6ac..9e4e229ac3 100644
--- a/apps/designer/app/designer/features/style-panel/shared/get-final-value.ts
+++ b/apps/designer/app/designer/features/style-panel/shared/get-final-value.ts
@@ -27,7 +27,10 @@ export const getFinalValue = ({
if (
currentValue &&
currentValue.type === "unit" &&
- isValid(property, toValue(currentValue)) === false
+ isValid(
+ property,
+ toValue({ ...currentValue, value: Math.abs(currentValue.value) })
+ ) === false
) {
return { ...(currentValue as unknown as InvalidValue), type: "invalid" };
}
diff --git a/packages/design-system/src/components/panel.tsx b/packages/design-system/src/components/panel.tsx
index d4abe937ef..414018ad6e 100644
--- a/packages/design-system/src/components/panel.tsx
+++ b/packages/design-system/src/components/panel.tsx
@@ -4,7 +4,8 @@ export const panelStyles = css({
overflow: "auto",
backgroundColor: "$slate4",
borderRadius: "$1",
- boxShadow: "0px 2px 7px rgba(0, 0, 0, 0.1), 0px 5px 17px rgba(0, 0, 0, 0.15)",
+ boxShadow:
+ "0px 2px 7px rgba(0, 0, 0, 0.1), 0px 5px 17px rgba(0, 0, 0, 0.15), inset 0 0 1px 1px $colors$slate1, 0 0 0 1px $colors$slate8",
});
export const Panel = styled("div", panelStyles);