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: Fix transitions for ephemeral changes (#3059)

Oleg Isonen870466fc29db
diff --git a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-content.tsx b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-content.tsx
index 4ea26480e1..8451b25895 100644
--- a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-content.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-content.tsx
@@ -24,7 +24,10 @@ import {
type ExtractedTransitionProperties,
} from "@webstudio-is/css-data";
import { InfoCircleIcon } from "@webstudio-is/icons";
-import type { DeleteProperty } from "../../shared/use-style-data";
+import type {
+ DeleteProperty,
+ StyleUpdateOptions,
+} from "../../shared/use-style-data";
import { type IntermediateStyleValue } from "../../shared/css-value-input";
import { TransitionProperty } from "./transition-property";
import { TransitionTiming } from "./transition-timing";
@@ -52,6 +55,7 @@ export const TransitionContent = ({
const { property, timing, delay, duration } =
useMemo<ExtractedTransitionProperties>(() => {
+ // @todo remove the effect from useMemo
setIntermediateValue({ type: "intermediate", value: transition });
return extractTransitionProperties(layer);
}, [layer, transition]);
@@ -95,13 +99,15 @@ export const TransitionContent = ({
setIntermediateValue(undefined);
};
- const handlePropertyUpdate = (params: ExtractedTransitionProperties) => {
+ const handlePropertyUpdate = (
+ params: ExtractedTransitionProperties,
+ options: StyleUpdateOptions = { isEphemeral: false }
+ ) => {
const value: Array<UnitValue | KeywordValue> = Object.values({
...{ property, duration, delay, timing },
...params,
}).filter<UnitValue | KeywordValue>(
- (item): item is UnitValue | KeywordValue =>
- item !== null && item !== undefined
+ (item): item is UnitValue | KeywordValue => item != null
);
const newLayer: TupleValue = { type: "tuple", value };
@@ -110,7 +116,9 @@ export const TransitionContent = ({
value: toValue(newLayer),
});
- onEditLayer(index, { type: "layers", value: [newLayer] });
+ if (options.isEphemeral === false) {
+ onEditLayer(index, { type: "layers", value: [newLayer] });
+ }
};
return (
@@ -161,11 +169,11 @@ export const TransitionContent = ({
deleteProperty={() => {
handlePropertyUpdate({ duration });
}}
- setValue={(value) => {
+ setValue={(value, options) => {
if (value === undefined) {
return;
}
- handlePropertyUpdate({ duration: value });
+ handlePropertyUpdate({ duration: value }, options);
}}
/>
@@ -197,11 +205,11 @@ export const TransitionContent = ({
label={transitionDurationConfig.label}
keywords={transitionDelayKeywords}
deleteProperty={() => handlePropertyUpdate({ delay })}
- setValue={(value) => {
+ setValue={(value, options) => {
if (value === undefined) {
return;
}
- handlePropertyUpdate({ delay: value });
+ handlePropertyUpdate({ delay: value }, options);
}}
/>
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 c46299d481..67c40433ce 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
@@ -216,14 +216,12 @@ const useHandleKeyDown =
ignoreUpDownNumeric,
value,
onChange,
- onChangeComplete,
onKeyDown,
}: {
ignoreEnter: boolean;
ignoreUpDownNumeric: boolean;
value: CssValueInputValue;
onChange: (value: CssValueInputValue) => void;
- onChangeComplete: (value: CssValueInputValue) => void;
onKeyDown: KeyboardEventHandler<HTMLInputElement>;
}) =>
(event: KeyboardEvent<HTMLInputElement>) => {
@@ -235,7 +233,7 @@ const useHandleKeyDown =
// Do not prevent downshift behaviour on item select
if (ignoreEnter === false) {
if (event.key === "Enter") {
- onChangeComplete(value);
+ onChange(value);
}
}
@@ -591,9 +589,8 @@ export const CssValueInput = ({
isUnitsOpen || (isOpen && !menuProps.empty && highlightedIndex !== -1),
// Do not change the number value on the arrow up/down if any menu is opened
ignoreUpDownNumeric: isUnitsOpen || isOpen,
- onChangeComplete: (value) => onChangeComplete(value, "enter"),
+ onChange: (value) => onChangeComplete(value, "enter"),
value,
- onChange: props.onChange,
onKeyDown: inputProps.onKeyDown,
});