Skip to content

Block styles: reflect inherited global styles values in block appearance controls #64670

@ramonjd

Description

@ramonjd

The tracking issue logs tasks associated primarily with the following issue:

Blocks can "inherit" styles from theme.json and user global styles. These styles are loaded into the Block Editor as global styles CSS, meaning that block will display its inherited styles in the editor canvas.

A block's design tool controls however only reflect applied block-level styles and not any global styles values.

Consequently, even though a block may appear to have, for example, red text in the Block Editor canvas (assuming that style is defined in theme.json), the block's color controls will feature empty values.

To avoid confusion to users, a block's style controls should reflect, as much as possible, the styles that a block inherits.

Constraints

The tracking issue is deliberately limited in scope to displaying values from the merged theme.json/global styles object.

Enqueued stylesheets and theme.json custom CSS for example will affect a block's appearance in the editor canvas but they cannot be reliably parsed. Similarly, other styles inherited via the CSS cascade such as a parent block's inner element styles, or a parent with block style variation applied's inner block type styles, would likely require querying the browser element itself.

A possible "Phase 2" could be to test the performance of extracting values using getComputedStyle().

Tasks (WIP)

  • Design a global styles inheritance hierarchy map, e.g., Root Global > Root Element > Block > Block Element > Block style variations. See: Styles: show a hierarchy of styles clearly (theme, user, global unspecific, global specific, local, etc) #49278
  • Create a hook/function to parse and structure merged global styles config values (base + theme + user) according to an inheritance map.
  • Users should have "read" access to global styles endpoints
  • Ensure that preset values such as colors and font sizes are correctly parsed and reflected in the controls.
  • Ensure that dynamic values such as theme.json "ref" pointers or relative paths are resolved. E.g., see this comment.
  • Migrate block controls to display inherited values
    • Color
    • Spacing
    • Typography
    • Background
    • Border
    • Shadow
    • Layout
    • ...

A corollary, and follow-up issue, is to enable "unsetting" global styles at the block level:

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    Global StylesAnything related to the broader Global Styles efforts, including Styles Engine and theme.json[Feature] Design ToolsTools that impact the appearance of blocks both to expand the number of tools and improve the experi[Status] In ProgressTracking issues with work in progress[Type] Tracking IssueTactical breakdown of efforts across the codebase and/or tied to Overview issues.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions