Make WordPress Core

Opened 8 months ago

Closed 4 months ago

Last modified 4 months ago

#64974 closed enhancement (fixed)

Block Supports: Add background gradient support that can combine with background images

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

Description

This ticket tracks the backport of PHP files for the following Gutenberg update:

​https://github.com/WordPress/gutenberg/pull/75859

Adds background.gradient as a new block support, enabling blocks to have a gradient picker in the Background panel. This is separate from the existing color.gradient in the Color panel and allows blocks to combine a background gradient with a background image via comma-separated background-image CSS values.

The ability to move away from the shorthand background CSS property for block supports is also required to unblock further design tooling improvements such as text gradients.

Change History (13)

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


8 months ago
#1

  • Keywords has-patch has-unit-tests added

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

This PR brings the PHP changes from the following Gutenberg PR to core:

WordPress/gutenberg#72628

## Description

Adds background.gradient as a new block support, enabling blocks to combine a background gradient with a background image via comma-separated
background-image CSS values (e.g., background-image: linear-gradient(...), url(...)).

Currently, the only way to apply a gradient is through color.gradient, which renders as a background CSS shorthand and conflicts with background image
properties. By introducing background.gradient (stored at style.background.gradient), gradients become part of the background style group, allowing the
style engine to combine gradient and image values without conflict.

See: WordPress/gutenberg#32787

## Testing

  1. Ensure PHP unit tests pass: `npm run test:php -- --filter="Tests_Block_Supports_WpRenderBackgroundSupport|Tests_Block_Supports_Colors|Tests_wpStyleEngine|test_get_background_gradient|test_remove_insecure_p roperties_allows_combined|test_remove_insecure_properties_allows_background_gradient|test_get_settings_appearance_true"`
  2. In a theme.json file, define a background gradient for the Group block using the new styles.blocks.core/group.background.gradient property (e.g., "gradient": "linear-gradient(135deg, #000 0%, #fff 100%)"). Verify the gradient renders correctly on the frontend.
  3. Also set a backgroundImage on the same Group block and confirm both values combine into a single background-image CSS declaration.
  4. Verify existing style.color.gradient support continues to work on blocks that don't opt into background.gradient.
  5. On a block that supports both, set both style.color.gradient and style.background.gradient — confirm background.gradient takes precedence and the color.gradient shorthand is suppressed.

​@ramonopoly commented on ​PR #11384:


5 months ago
#2

Sorry I've kept this waiting for so long. Just rediscovered after working on ​https://github.com/WordPress/wordpress-develop/pull/12361

I can give it a test tomorrow - is there anything we're waiting on to get this?

​@aaronrobertshaw commented on ​PR #11384:


5 months ago
#3

I believe everything should be good to go with this but as it has sat for a while, I'll need to give it a rebase first

​@aaronrobertshaw commented on ​PR #11384:


5 months ago
#4

Actually, turns out I missed updating the core function to allow combined gradients and backgrounds properly via kses.

I've updated that now but the original Gutenberg PR only allowed modern color functions within gradients when combined with a background. I've tweaked that here so that it is consistent and they are supported for standalone gradients as well.

This will need backporting to Gutenberg so I'll spin up a PR doing that this evening or tomorrow.

​@aaronrobertshaw commented on ​PR #11384:


5 months ago
#5

I've backported to Gutenberg the changes here allowing modern color definitions within standalone gradients in ​https://github.com/WordPress/gutenberg/pull/79791

​@wildworks commented on ​PR #11384:


4 months ago
#6

I would appreciate it if you could proceed with this PR and commit it in time for the 7.1 Beta1 release on July 15.

​@ramonopoly commented on ​PR #11384:


4 months ago
#7

@aaronrobertshaw do you need help landing this one?

​@ramonopoly commented on ​PR #11384:


4 months ago
#8

I rebased this and retested. I think it's good to go.

​@ramonopoly commented on ​PR #11384:


4 months ago
#9

I'll go ahead and commit this today

#10 @ramonopoly
4 months ago

  • Owner set to ramonopoly
  • Resolution → fixed
  • Status new → closed

In 62718:

Block Supports: Add background gradient support that can combine with background image

Adds background.gradient as a new block support, enabling blocks to combine a background gradient with a background image via comma-separated background-image CSS values (e.g., background-image: linear-gradient(...), url(...)).

Before, the only way to apply a gradient is through color.gradient, which renders as a background CSS shorthand and conflicts with background image
properties. By introducing background.gradient (stored at style.background.gradient), gradients become part of the background style group, allowing the style engine to combine gradient and image values without conflict.

Props aaronrobertshaw, ramonopoly, wildworks.

Fixes #64974.

​@ramonopoly commented on ​PR #11384:


4 months ago
#11

Comitted in r62718 / 6b190c64b2985841020e653da66cf8c1246909d6

​@aaronrobertshaw commented on ​PR #11384:


4 months ago
#12

Thank you very much for picking this up and getting it committed @ramonjd 🙇

​@ramonopoly commented on ​PR #11384:


4 months ago
#13

No worries. It's a long time coming, thanks for working on it and fixing it

Note: See TracTickets for help on using tickets.