diff --git a/apps/builder/app/builder/features/style-panel/property-label.test.tsx b/apps/builder/app/builder/features/style-panel/property-label.test.tsx
index 0ddb96f619..f8706179e7 100644
--- a/apps/builder/app/builder/features/style-panel/property-label.test.tsx
+++ b/apps/builder/app/builder/features/style-panel/property-label.test.tsx
@@ -2,11 +2,111 @@ import { act } from "react-dom/test-utils";
import { afterEach, expect, test } from "vitest";
import { userEvent } from "@vitest/browser/context";
import { TooltipProvider } from "@webstudio-is/design-system";
+import { createDefaultPages } from "@webstudio-is/project-build";
+import { getTagStyleId } from "@webstudio-is/sdk";
+import {
+ selectInstance,
+ $selectedInstanceSelector,
+ $selectedPageId,
+ $selectedStyleSources,
+ $selectedStyleState,
+ $temporaryTagStyleId,
+} from "~/shared/nano-states";
+import {
+ $breakpoints,
+ $instances,
+ $pages,
+ $styleSources,
+} from "~/shared/sync/data-stores";
+import type { ComputedStyleDecl } from "~/shared/style-object-model";
import { createAssetManagerTestRenderer } from "~/builder/shared/asset-manager/test-utils";
-import { PropertyInlineLabel } from "./property-label";
+import { PropertyInfo, PropertyInlineLabel } from "./property-label";
const renderer = createAssetManagerTestRenderer();
-afterEach(renderer.cleanup);
+afterEach(() => {
+ renderer.cleanup();
+ selectInstance(undefined);
+ $selectedPageId.set(undefined);
+ $pages.set(undefined);
+ $instances.set(new Map());
+ $styleSources.set(new Map());
+ $breakpoints.set(new Map());
+ $selectedStyleSources.set(new Map());
+ $selectedStyleState.set(undefined);
+ $temporaryTagStyleId.set(undefined);
+});
+
+test("nested source badge keeps a valid ancestor selection and is cascaded", async () => {
+ const pages = createDefaultPages({ rootInstanceId: "container" });
+ $pages.set(pages);
+ $selectedPageId.set(pages.homePageId);
+ $instances.set(
+ new Map([
+ [
+ "container",
+ {
+ type: "instance" as const,
+ id: "container",
+ component: "Box",
+ children: [{ type: "id" as const, value: "heading" }],
+ },
+ ],
+ [
+ "heading",
+ {
+ type: "instance" as const,
+ id: "heading",
+ component: "Heading",
+ children: [],
+ },
+ ],
+ ])
+ );
+ const tagStyleId = getTagStyleId("div");
+ $styleSources.set(
+ new Map([[tagStyleId, { type: "tag", id: tagStyleId, tag: "div" }]])
+ );
+ $breakpoints.set(new Map([["base", { id: "base", label: "Base" }]]));
+ selectInstance(["heading", "container"]);
+ const value = { type: "keyword", value: "red" } as const;
+ const styles: ComputedStyleDecl[] = [
+ {
+ property: "color",
+ source: {
+ name: "remote",
+ instanceId: "container",
+ styleSourceId: tagStyleId,
+ breakpointId: "base",
+ state: " h2:hover",
+ },
+ cascadedValue: value,
+ computedValue: value,
+ usedValue: value,
+ },
+ ];
+ const container = renderer.render(
+
+ );
+
+ const sourceButton = Array.from(container.querySelectorAll("button")).find(
+ (button) => button.textContent?.includes("div")
+ );
+ expect(sourceButton).toBeDefined();
+ await act(async () => userEvent.click(sourceButton!));
+
+ expect($selectedInstanceSelector.get()).toEqual(["container"]);
+ expect($selectedStyleSources.get().get("container")).toBe(tagStyleId);
+ expect($selectedStyleState.get()).toBe(" h2:hover");
+ expect($temporaryTagStyleId.get()).toBe(tagStyleId);
+ expect(container.textContent).toContain("Cascaded:");
+ $instances.set(new Map($instances.get()));
+ expect($selectedInstanceSelector.get()).toEqual(["container"]);
+});
test("inline property labels offer keyboard-accessible information without a reset action", async () => {
const container = renderer.render(
diff --git a/apps/builder/app/builder/features/style-panel/property-label.tsx b/apps/builder/app/builder/features/style-panel/property-label.tsx
index 1da60216fc..0b090bebe0 100644
--- a/apps/builder/app/builder/features/style-panel/property-label.tsx
+++ b/apps/builder/app/builder/features/style-panel/property-label.tsx
@@ -1,5 +1,6 @@
import { useStore } from "@nanostores/react";
import { useState, type ReactNode } from "react";
+import { ROOT_INSTANCE_ID } from "@webstudio-is/sdk";
import { AlertIcon, ResetIcon } from "@webstudio-is/icons";
import { toValue, type CssProperty } from "@webstudio-is/css-engine";
import { propertiesData } from "@webstudio-is/css-data";
@@ -159,7 +160,12 @@ export const PropertyInfo = ({
if (target === undefined) {
return;
}
- selectInstance(target.instanceSelector);
+ const targetSelector = target.instanceSelector;
+ selectInstance(
+ targetSelector.length > 1 && targetSelector.at(-1) === ROOT_INSTANCE_ID
+ ? targetSelector.slice(0, -1)
+ : targetSelector
+ );
if (source.styleSourceId) {
if (styleSources.get(source.styleSourceId)?.type === "tag") {
$temporaryTagStyleId.set(source.styleSourceId);
@@ -211,13 +217,15 @@ export const PropertyInfo = ({
selectedInstanceId !== undefined &&
(sourceColor === "remote" || sourceColor === "preset")
) {
- const sourceInstances = styles
- .filter((style) => style.source.name === sourceColor)
- .map((style) => style.source.instanceId);
+ const matchingStyles = styles.filter(
+ (style) => style.source.name === sourceColor
+ );
if (
- sourceInstances.every(
- (instanceId) =>
- instanceId !== undefined && instanceId !== selectedInstanceId
+ matchingStyles.every(
+ ({ source }) =>
+ source.instanceId !== undefined &&
+ source.instanceId !== selectedInstanceId &&
+ source.state?.startsWith(" ") !== true
)
) {
sourceLabel = sourceColor === "remote" ? "Inherited" : "Preset";
@@ -227,7 +235,9 @@ export const PropertyInfo = ({
: "Comes from a Webstudio component default on an ancestor element.";
} else if (
sourceColor === "remote" &&
- sourceInstances.every((instanceId) => instanceId === selectedInstanceId)
+ matchingStyles.every(
+ ({ source }) => source.instanceId === selectedInstanceId
+ )
) {
sourceDescription =
"Comes from another style source, breakpoint, or state on this element.";
diff --git a/apps/builder/app/builder/features/style-panel/shared/model.tsx b/apps/builder/app/builder/features/style-panel/shared/model.tsx
index fc563f17ee..9e5a582d7b 100644
--- a/apps/builder/app/builder/features/style-panel/shared/model.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/model.tsx
@@ -27,6 +27,7 @@ import {
$propsIndex,
$selectedBreakpoint,
$selectedInstanceStates,
+ $selectedInstanceStatesByInstanceId,
$selectedOrLastStyleSourceSelector,
} from "~/shared/nano-states";
import { $breakpoints } from "~/shared/sync/data-stores";
@@ -233,6 +234,7 @@ export const $styleObjectModel = computed(
$instanceComponents,
$matchingBreakpoints,
$selectedInstanceStates,
+ $selectedInstanceStatesByInstanceId,
],
(
styles,
@@ -242,7 +244,8 @@ export const $styleObjectModel = computed(
instanceTags,
instanceComponents,
matchingBreakpoints,
- matchingStates
+ matchingStates,
+ matchingStatesByInstanceId
): StyleObjectModel => {
const tagStyleIds = new Map();
for (const source of styleSources.values()) {
@@ -259,6 +262,7 @@ export const $styleObjectModel = computed(
instanceComponents,
matchingBreakpoints,
matchingStates,
+ matchingStatesByInstanceId,
};
}
);
diff --git a/apps/builder/app/builder/features/style-panel/style-source/style-source-input.test.tsx b/apps/builder/app/builder/features/style-panel/style-source/style-source-input.test.tsx
index de006a039d..f3924fd98c 100644
--- a/apps/builder/app/builder/features/style-panel/style-source/style-source-input.test.tsx
+++ b/apps/builder/app/builder/features/style-panel/style-source/style-source-input.test.tsx
@@ -190,6 +190,44 @@ test("describes Copy and keeps the style source menu width stable", () => {
}
});
+test("describes the supported selectors when Add more receives focus", () => {
+ const container = document.createElement("div");
+ document.body.appendChild(container);
+ const root = createRoot(container);
+ try {
+ act(() =>
+ root.render(
+ {}}
+ selectedItemSelector={undefined}
+ item={{
+ id: "tag-style:button",
+ label: "button",
+ source: "tag",
+ disabled: false,
+ locked: false,
+ states: [],
+ }}
+ hasStyles={false}
+ states={[]}
+ />
+ )
+ );
+ const input = document.querySelector(
+ "[role=menu] form input"
+ );
+ expect(input).not.toBeNull();
+ act(() => input?.focus());
+ expect(document.querySelector("[role=menu]")?.textContent).toContain(
+ "Start with a tag, such as h2, h2:hover, or h2::before"
+ );
+ } finally {
+ act(() => root.unmount());
+ container.remove();
+ }
+});
+
test("disables Copy when a source has no declarations", () => {
const container = document.createElement("div");
document.body.appendChild(container);
diff --git a/apps/builder/app/builder/features/style-panel/style-source/style-source-menu.tsx b/apps/builder/app/builder/features/style-panel/style-source/style-source-menu.tsx
index 82c1eef47a..27cd1b1f65 100644
--- a/apps/builder/app/builder/features/style-panel/style-source/style-source-menu.tsx
+++ b/apps/builder/app/builder/features/style-panel/style-source/style-source-menu.tsx
@@ -124,6 +124,8 @@ const menuActionDescriptions = {
unlock: "Allow style changes on this token again.",
detach: "Remove this token from the element without deleting it.",
delete: "Permanently delete this token and all its styles from the project.",
+ addMore:
+ "Use :hover or [data-state=open] to style this element in a state, and ::before to style its pseudo-element. Start with a tag, such as h2, h2:hover, or h2::before, to style nested elements.",
} as const;
type MenuAction = keyof typeof menuActionDescriptions;
@@ -172,11 +174,13 @@ const getSelectorDescription = (selector: string | null | undefined) => {
const SelectorCombobox = ({
existingSelectors,
- allowDescendants,
+ onFocus,
+ onBlur,
onSelect,
}: {
existingSelectors: string[];
- allowDescendants: boolean;
+ onFocus: () => void;
+ onBlur: () => void;
onSelect: (selector: string) => void;
}) => {
const [value, setValue] = useState("");
@@ -184,10 +188,10 @@ const SelectorCombobox = ({
const handleSubmit = (selector: string) => {
let normalizedSelector = selector;
- let validation = validateSelector(normalizedSelector, { allowDescendants });
- if (validation.success === false && allowDescendants) {
+ let validation = validateSelector(normalizedSelector);
+ if (validation.success === false) {
const tagSelector = ` ${selector}`;
- const tagValidation = validateSelector(tagSelector, { allowDescendants });
+ const tagValidation = validateSelector(tagSelector);
if (tagValidation.success && tagValidation.type === "tag") {
normalizedSelector = tagSelector;
validation = tagValidation;
@@ -202,14 +206,14 @@ const SelectorCombobox = ({
setValue("");
};
- const availableItems = allSelectors.filter(
- (selector) =>
- (allowDescendants || tags.includes(selector) === false) &&
- existingSelectors.every((s) => s.trim() !== selector)
+ const availableItems = allSelectors.filter((selector) =>
+ existingSelectors.every((s) => s.trim() !== selector)
);
return (