Make WordPress Core

Opened 4 weeks ago

Last modified 16 hours ago

#66094 new enhancement

Editor: Add a background clip block support to facilitate text gradients

Reported by: aaronrobertshaw Owned by:
Priority: normal Milestone: 7.2
Component: Editor Version: trunk
Severity: normal Keywords: gutenberg-merge has-patch has-unit-tests
Cc: Focuses:

Description

Backport of Gutenberg PR ​https://github.com/WordPress/gutenberg/pull/77141.

Adds a background.backgroundClip block support, so a block can set which box its background is painted into: border-box, padding-box, content-box, or the text itself. Clipping to the text is what gives blocks a gradient text fill, since CSS has no gradient colour.

For the text value the style engine also emits -webkit-background-clip and
-webkit-text-fill-color, and the block skips the has-background class because
nothing paints the block's background. For the box values only the fill colour
is reset, because -webkit-background-clip is an alias of background-clip in
Chromium and resetting it would discard the value.

The setting is not part of appearance tools. A theme opts in by setting
settings.background.backgroundClip, either true or an array of the values it
wants to offer.

The editor controls and the core/heading and core/paragraph opt-ins arrive with
the next Gutenberg package update.

Change History (3)

This ticket was mentioned in ​PR #13491 on ​WordPress/wordpress-develop by ​@aaronrobertshaw.


4 weeks ago
#1

  • Keywords has-patch has-unit-tests added

Backport of Gutenberg PR ​https://github.com/WordPress/gutenberg/pull/77141

Trac ticket: https://core.trac.wordpress.org/ticket/66094

Adds a background.backgroundClip block support, so a block can set which box its background is painted into: border-box, padding-box, content-box, or the text itself. Clipping to the text is what gives blocks a gradient text fill.

This PR backports:

  • the backgroundClip definition and its value parser in WP_Style_Engine,
  • gradient classnames moving to a classnames_func callback there, which keeps the file in sync with Gutenberg. Behaviour is unchanged,
  • the background.backgroundClip setting and style in WP_Theme_JSON, its CSS property mapping, and the vendor prefixed declarations that go with it,
  • background-clip and its vendor prefixed companions added to the KSES safe style allowlist,
  • the has-background class being skipped when the background is clipped to the text,
  • and the accompanying style engine and background block support tests.

For the text value the engine also emits -webkit-background-clip and -webkit-text-fill-color. For the box values only the fill color is reset, because -webkit-background-clip is an alias of background-clip in Chromium and resetting it would discard the value set above.

The editor controls, and the core/heading and core/paragraph opt-ins, arrive with the next Gutenberg package update.

## Testing instructions

No block opts in yet and there is no control in the editor, so test the generated global styles.

  1. Add this to a block theme's theme.json:
"styles": {
	"blocks": {
		"core/heading": {
			"background": {
				"gradient": "linear-gradient(to right,#ff0000,#0000ff)",
				"backgroundClip": "text"
			}
		},
		"core/group": {
			"background": {
				"gradient": "linear-gradient(to right,#ff0000,#0000ff)",
				"backgroundClip": "content-box"
			}
		}
	}
}
  1. Load a page with a Heading and a Group and check the global styles. They should contain:
:root :where(.wp-block-heading){background-image: linear-gradient(to right,#ff0000,#0000ff);background-clip: text;-webkit-background-clip: text;-webkit-text-fill-color: transparent;}
:root :where(.wp-block-group){background-image: linear-gradient(to right,#ff0000,#0000ff);background-clip: content-box;-webkit-text-fill-color: unset;}
  1. The heading should render with the gradient on its letters. Give the group padding and a thick dashed border, and its gradient should stop at the inner edge of the padding.

Without the change neither background-clip declaration is generated, so both render as a plain background gradient filling the whole block.

## Use of AI

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5
Used for: the mechanical port and polishing this description

​@aaronrobertshaw commented on ​PR #13491:


2 weeks ago
#2

FYI, things are evolving on the Gutenberg PR this backports. I'll mark this as in draft until that stabilizes.

​@peterwilsoncc commented on ​PR #13491:


16 hours ago
#3

@aaronrobertshaw Is this ready for review now that ​https://github.com/WordPress/gutenberg/pull/77141 has merged?

Note: See TracTickets for help on using tickets.