Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting a default gradient on a block prevents user from changing background to a solid color #47391

Open
jakeparis opened this issue Jan 24, 2023 · 6 comments
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json Needs Design Needs design efforts. [Type] Bug An existing feature does not function as intended

Comments

@jakeparis
Copy link
Contributor

Description

If you use theme.json to set a default gradient on a block, if the user attempts to set a solid background color of that block from within the editor, the color doesn't change in the editor. The modified background color does show up on the front-end.

I've tried this on both the button block and the group block with the same result.

Step-by-step reproduction instructions

  1. Set a default gradient on a block
"styles": {
  "blocks": {
    "core/button": {
      "color": {
        "gradient": "var(--wp--preset--gradient--blush-bordeaux)"
      },
    "core/group": {
      "color": {
        "gradient": "var(--wp--preset--gradient--blush-bordeaux)"
      }
    }
  }
}
  1. Insert that block into the block editor
  2. Attempt to set a solid background color on the block
  3. The background of the block doesn't change.
  4. Save, and see that the front-end does have your modified background color.

Screenshots, screen recording, code snippet

No response

Environment info

  • Wordpress 6.1
  • not using gutenberg plugin

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@jakeparis jakeparis changed the title Setting a default gradient on a block blocks user changing background to a color Setting a default gradient on a block prevents user from changing background to a solid color Jan 24, 2023
@kathrynwp kathrynwp added Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Bug An existing feature does not function as intended labels Jan 25, 2023
@annezazu annezazu moved this to ❓ Triage in WordPress 6.2 Editor Tasks Jan 26, 2023
@ndiego
Copy link
Member

ndiego commented Jan 27, 2023

I can confirm this. Whether you apply the gradient in theme.json, or from within the Site Editor, the gradient overrides the background color. In my tests, it occurs in both the Editor and the front end because background takes priority over background-color.

gradient-bug

@ndiego ndiego moved this from ❓ Triage to 📥 Todo in WordPress 6.2 Editor Tasks Jan 27, 2023
@glendaviesnz
Copy link
Contributor

glendaviesnz commented Jan 30, 2023

This is an interesting problem as this is just reflecting how CSS is expected to work, ie. background-color is often a fallback setting to show only if gradient or image is not set. It still feels wrong from an average user UX perspective though.

It could be fixed by changing the background color presets to also reset the background:

background: none !important
background-color: var(--wp...) !important

but we risk inadvertently removing other theme/global CSS background settings this way. Another option to reduce this risk would be to move the gradients from background to background-image and that way only background-image needs to be reset:

background-image: none !important
background-color: var(--wp...) !important

This still has the potential to reset background-image in cases where the user may be expecting the background color to only be acting as a fallback in cases where the image may not load.

It gets more complicated in the case of custom colors as these are added to the post content as inline styles, so adding a new background-image reset to these would require deprecations for all the blocks currently supporting background colors.

Do we need an extra attribute flag for background color, eg. Override background image/gradient, that way a user has to explicitly choose to override the default CSS behavior? I think this would also get around the block deprecations issue as the new property would only be expected if the new flag was set.

I could be overlooking a simpler solution, or maybe I am overthinking the potential issues of resetting the background if a background color is set?

If I am not overlooking a simpler solution then this may need to be punted from 6.2 given the timeframe.

@glendaviesnz glendaviesnz added the Needs Design Needs design efforts. label Jan 30, 2023
@glendaviesnz
Copy link
Contributor

Design - this needs some thought about how the background color support should work when a background gradient or image is present, as the default CSS behavior is for the background color to act as a fallback rather than an override.

Do we need a toggle on the background color setting so users can explicitly choose for the background color to act as an override. N.B This would probably require moving gradient to background-image property instead of background

@jakeparis
Copy link
Contributor Author

I think it would be unfortunately to add yet another toggle or config option for a background color to override this or that.

Using !important seems to only ever cause headaches further down the road.

I am not intimately familiar with how the css is being built on the editor side of things, but I think the best thing would be if the generic background property was never used, and instead the more specific background-color, background-image was always used instead. It would at least make the behavior more predictable.

If the css from theme.json is printed in a <style> block, and the editor is adding styles inline, perhaps the default styles could be set up with something like:

div:not([style*="background-image"]) {
  /* default background */
  background-image: linear-gradient();
}

(example)

@ndiego
Copy link
Member

ndiego commented Feb 22, 2023

If I am not overlooking a simpler solution then this may need to be punted from 6.2 given the timeframe.

Given the complexity of this issue and the final Beta release is next Tuesday, I recommend we punt from 6.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json Needs Design Needs design efforts. [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

5 participants