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: Allow transitions on pseudo-elements (#5771)

Oleg Isonen00bdc9a04ec5
diff --git a/apps/builder/app/builder/features/style-panel/sections/transitions/transitions.test.ts b/apps/builder/app/builder/features/style-panel/sections/transitions/transitions.test.ts
new file mode 100644
index 0000000000..908ab56805
--- /dev/null
+++ b/apps/builder/app/builder/features/style-panel/sections/transitions/transitions.test.ts
@@ -0,0 +1,17 @@
+import { describe, expect, test } from "vitest";
+import { __testing__ } from "./transitions";
+
+const { canAddTransitionToStyleState } = __testing__;
+
+describe("canAddTransitionToStyleState", () => {
+ test("allows local styles and pseudo-elements", () => {
+ expect(canAddTransitionToStyleState(undefined)).toBe(true);
+ expect(canAddTransitionToStyleState("::before")).toBe(true);
+ expect(canAddTransitionToStyleState("::after")).toBe(true);
+ });
+
+ test("keeps transitions disabled for pseudo-classes", () => {
+ expect(canAddTransitionToStyleState(":hover")).toBe(false);
+ expect(canAddTransitionToStyleState(":focus")).toBe(false);
+ });
+});
diff --git a/apps/builder/app/builder/features/style-panel/sections/transitions/transitions.tsx b/apps/builder/app/builder/features/style-panel/sections/transitions/transitions.tsx
index 1bd164829e..5e77a8acb8 100644
--- a/apps/builder/app/builder/features/style-panel/sections/transitions/transitions.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/transitions/transitions.tsx
@@ -5,7 +5,7 @@ import {
SectionTitleButton,
Tooltip,
} from "@webstudio-is/design-system";
-import { propertiesData } from "@webstudio-is/css-data";
+import { isPseudoElement, propertiesData } from "@webstudio-is/css-data";
import {
toValue,
type CssProperty,
@@ -42,6 +42,9 @@ export { transitionLongHandProperties as properties };
const label = "Transitions";
+const canAddTransitionToStyleState = (state: undefined | string): boolean =>
+ state === undefined || isPseudoElement(state);
+
const getTransitionLayers = (
styles: ComputedStyleDecl[],
property: (typeof transitionLongHandProperties)[number]
@@ -93,9 +96,9 @@ export const Section = () => {
$selectedOrLastStyleSourceSelector
);
- const isStyleInLocalState =
+ const canAddTransition =
selectedOrLastStyleSourceSelector &&
- selectedOrLastStyleSourceSelector.state === undefined;
+ canAddTransitionToStyleState(selectedOrLastStyleSourceSelector.state);
const styles = useComputedStyles(transitionLongHandProperties);
const dots = getDots(styles);
@@ -113,13 +116,13 @@ export const Section = () => {
suffix={
<Tooltip
content={
- isStyleInLocalState === false
- ? "Transitions can only be added in local state"
+ canAddTransition === false
+ ? "Transitions can only be added in local state or pseudo-elements"
: "Add a transition"
}
>
<SectionTitleButton
- disabled={readonly || isStyleInLocalState === false}
+ disabled={readonly || canAddTransition === false}
prefix={<PlusIcon />}
onClick={() => {
setIsOpen(true);
@@ -153,3 +156,7 @@ export const Section = () => {
</CollapsibleSectionRoot>
);
};
+
+export const __testing__ = {
+ canAddTransitionToStyleState,
+};