mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-02 13:25:40 +09:00
fix: Show scoped Tag colors on selected descendants (#6677)
When an H2 gets its color from a Tag selector on its container, selecting the H2 can show black in the Style panel. The panel now shows the matching color. A Token or Local style on the H2 can still override the container's Tag selector. ## Plan and progress - [x] Reproduce the selected H2 showing the container color instead of its nested Tag color. - [x] Give descendant Tag selectors the intended CSS specificity in Builder and published CSS. - [x] Include matching ancestor Tag declarations in the Style panel's color calculation. - [x] Cover the selected H2 and regular and atomic CSS output with focused tests. - [x] Review documentation impact and update the Tag styles and selectors guides. - [x] Match the panel's competing ancestor Tag rules to CSS breakpoint and stylesheet order. - [x] Match the editing preview's selector specificity to the saved rule. - [x] Use the descendant separator directly when detecting nested selectors. - [x] Allow the same supported selector forms in Tag, Token, and Local sources. - [x] Match global Tag descendant styles in the editing preview and Style panel. - [x] Document nested Tag selector examples in the Tag styles guide. - [x] Explain supported selectors in Add more while its input is focused. - [x] Review and simplify nested state matching; preserve the entered selector text. - [x] Consolidate cascade declaration lookup and reuse the validated selector parse result. - [x] Align Builder and MCP selector entry with one validation rule; preserve saved selectors. - [x] Fix nested-selector source badges and preserve valid instance selection. - [x] Keep descendant conditions scoped to the matched element during inheritance. - [x] Match saved nested selectors regardless of tag casing or leading whitespace. - [ ] Verify both fixes, resolve review threads, and review CI. The panel model needs ancestor matching because it computes styles without querying the rendered element. The complete PR adds about 195 net non-test lines. The added work covers selector entry, active nested states, and matching Tag rules in the panel; the saved CSS output already supported nested tags. CSS generation uses `:where()` around the container selector so the nested tag can override the global tag style while the H2's own Token can override the nested tag style. No stored data changes. Checks passed locally: focused Builder style source, active state, panel model, and canvas preview tests; CSS data and runtime tests; Builder, CSS data, and project-build typechecks; lint, formatting, and `git diff --check`. The focused Add more menu was checked in Storybook in both themes. CI passed for commit `838cf4293f`; CI for `224f11e274` is pending. The full Builder app suite was started but stopped after it stopped producing results; the two affected suites passed independently. This follow-up adds 67 net non-test lines to track matching states by instance and match saved descendant selectors using the shared parser. No fixture inputs or generated fixture outputs changed. Ref #5657
This commit is contained in:
1 parent
2b9ce760bb
commit
b0d7cc2e7b
30 files changed
+1071
-338
No files matched your search
@@ -45,16 +45,14 @@ States are CSS pseudo-classes that apply styles when a condition is true, such a
|
||||
|
||||
### Custom states
|
||||
|
||||
You can type any valid CSS pseudo-class into the Style Sources dropdown. If it's not in the predefined list, Webstudio will accept it as a custom selector.
|
||||
Use **Add more** in a Tag, Token, or Local style source to enter a selector that is not in the list.
|
||||
|
||||
{% hint style="info" %}
|
||||
Custom states can target descendants while staying scoped to the selected instance. For example, `:hover .button` targets descendants with the [custom class](custom-classes-and-attributes.md) `button` while the selected instance is hovered, and `:hover > .icon` targets only direct children with the custom class `icon`.
|
||||
Start with `:` or `[` to target the current source's element or its pseudo-elements. For example, `:hover` applies while the element is hovered, `[data-state=open]` applies when its attribute matches, and `::before` targets its pseudo-element. You can combine conditions, such as `[data-state=open]:hover`.
|
||||
|
||||
You can also select a descendant tag in a Local source or Token. For example, `p` targets paragraphs inside that instance. A [Tag style](tag-styles.md) targets one tag across the site instead.
|
||||
Start with an HTML tag name to style that tag nested inside the current source's element. For example, `h2`, `h2:hover`, `h2[a="123"]`, and `h2::before` target nested headings. Quote numeric attribute values as in `a="123"`. A [Tag style](tag-styles.md) applies its nested tag selector across the site; a Token or Local source applies it only where that source is used.
|
||||
|
||||
Prefer [CSS variables for parent-child interactions](css-variables.md#parent-child-interactions). They keep each property on the child that uses it, can coordinate several children from one parent state, and do not couple the interaction to descendant classes or structure. Use a descendant custom state when the interaction specifically requires selector-based targeting.
|
||||
|
||||
Start a custom state with a pseudo-class, pseudo-element, or attribute selector for the selected instance. You can then use a descendant (` `) or child (`>`) combinator. A tag name on its own is treated as a descendant selector. Selector lists, class or ID selectors at the start, and sibling combinators (`+` and `~`) are rejected because they can target elements outside the selected instance.
|
||||
**Add more** accepts one nested tag with optional conditions. It does not accept multiple top-level selectors, direct class or ID selectors such as `.card` or `h2.card`, a second nested element, or combinators such as `>`, `+`, and `~`. For parent-child interactions, [CSS variables](css-variables.md#parent-child-interactions) let the parent change a value used by the child.
|
||||
{% endhint %}
|
||||
|
||||
## Pseudo-elements
|
||||
|
||||
@@ -10,7 +10,7 @@ description: Set site-wide styles for HTML tags such as div, h1, and button.
|
||||
|
||||
1. Select an instance on the canvas, such as a `div`.
|
||||
2. Open the **Style sources** field at the top of the Style panel.
|
||||
3. Select `div` under **Tag style**. Its source appears first in the field.
|
||||
3. Select `div` under **Tag**. Its source appears first in the field.
|
||||
4. Select that source and set a style. The Tag style is saved when you add its first style.
|
||||
|
||||
<picture>
|
||||
@@ -29,7 +29,7 @@ Open the Tag style's menu and choose a state such as `:hover` or `:focus-visible
|
||||
<img src="../../.gitbook/assets/tag-style-states-light.png" alt="div Tag style menu with Copy above hover and focus-visible states" width="240">
|
||||
</picture>
|
||||
|
||||
A Tag style targets its tag and state across the site. To style a descendant within one element instead, use a [custom state or selector](states-and-selectors.md#custom-states) on a Token or Local source.
|
||||
A Tag style targets its tag and state across the site. In **Add more**, `:hover`, `[data-state=open]`, and `::before` target the Tag style's own element. Enter an HTML tag to target a nested element on every matching instance: `h2`, `h2:hover`, `h2[a="123"]`, and `h2::before` are supported. The same [selector forms](states-and-selectors.md#custom-states) work in Token and Local sources, where they apply only to instances using that source.
|
||||
|
||||
## Copy and paste
|
||||
|
||||
|
||||
Reference in new issue
Block a user