-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Global styles: background UI controls #59454
Conversation
Size Change: +523 B (0%) Total Size: 1.72 MB
ℹ️ View Unchanged
|
8a1230d
to
847d0e5
Compare
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
659bfad
to
384d0bc
Compare
style={ value } | ||
inheritedValue={ inheritedValue } | ||
/> | ||
{ shouldShowBackgroundSizeControls && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is right... allow this panel if theme.json (and incoming block supports flag) has background.backgroundSize
set to true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it true
by default? I can see the controls in the global styles UI without changing anything in theme.json.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, something fishy is going on. It's true
by default, but I can't see from where 🙃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh face palm moment.
I forgot I added "backgroundImage"
and "backgroundSize"
to appearanceTools
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool, this is fun to play with! I've just added the "Needs Design Feedback" label, since it looks like there'll be a few things to figure out.
The main question for me in playing around with it is: what should the default size values be when someone first uploads or adds an image? Here's how it looks for me with a regular photo on a very tall template (it results in the image being very zoomed in):
Defaulting to Cover works nicely for the Group block, but in practice, it feels like at the root of the site, folks might rarely want to use either Cover or Contain, since it'll be pretty inconsistent depending on the height of the current page. So perhaps in the root of global styles, defaulting to Fixed might work better?
Also, in global styles, what do you think about displaying the size controls by default? It looked a bit empty to me in the initial state after adding an image:
Thank you for testing @andrewserong 🙇🏻
Fixed and no-repeat could work as a default - that's Agree that it would allow users to see the image they've added, regardless of size Then folks could change the settings themselves. It might also work for the theme.json side of things - Gutenberg setting the backgroundSize to
Can do. 👍🏻 I basically copied the post editor. |
I think so — worth having a play with and seeing how it feels. It'll be interesting to then think through once we've added an image, which is the first control we find we repeatedly reach for after that 🤔
Yeah, it does to me, too. It's funny how these things seem to become clearer once a PR is up. When interacting with a particular block in the post editor,
Nice one! |
384d0bc
to
b6292db
Compare
@andrewserong I started a PR to test it out: 👍🏻 |
ffdefdc
to
afa006d
Compare
Co-authored-by: Andrew Serong <[email protected]>
Thanks again @andrewserong
Oh, thanks for the nudge. I'd added that to my list but hadn't acknowledged it in the comments 👍🏻 It's in the works! |
No worries! Thanks again for all the detailed work here, it's such an exciting feature 😀 |
Cool cool yeah definitely let's not block this PR. Thanks for clarifying! |
Thanks again, everyone! Ongoing follow ups: |
I figured that might be the case :D
Seems a simple solution :) |
@ramonjd we might also consider naming this whole section "Background image" rather than just "Background", which may mislead users into believing they can set the background color here. |
* Refactor global styles and refactor existing background components * Porting over existing hook code to shared, global styles component. * Move tests, move styles, remove duplicate code from block support hook * Pull over changes to background.js from WordPress#59557 * Add default control values for block supports. The default backgroundSize value for block backgrounds is 'cover' * Resetting position if it's center and size is not contain. * Add background-image to INDIRECT_PROPERTIES_METADATA because the value is "indirectly" stored in an array, at least determined by multiple values in an array. --------- Co-authored-by: ramonjd <[email protected]> Co-authored-by: andrewserong <[email protected]> Co-authored-by: tellthemachines <[email protected]> Co-authored-by: jameskoster <[email protected]>
Great (and overdue) feature, which was missing in FSE Themes from start. (And existing in Classic Themes from start.) But without the "Fixed background" option like in Cover block, the result looks ... strange. |
It's the first item on the TODO list here for WordPress 6.6: |
* Refactor global styles and refactor existing background components * Porting over existing hook code to shared, global styles component. * Move tests, move styles, remove duplicate code from block support hook * Pull over changes to background.js from WordPress#59557 * Add default control values for block supports. The default backgroundSize value for block backgrounds is 'cover' * Resetting position if it's center and size is not contain. * Add background-image to INDIRECT_PROPERTIES_METADATA because the value is "indirectly" stored in an array, at least determined by multiple values in an array. --------- Co-authored-by: ramonjd <[email protected]> Co-authored-by: andrewserong <[email protected]> Co-authored-by: tellthemachines <[email protected]> Co-authored-by: jameskoster <[email protected]>
Dev Note 📓
#59354 (comment)
What?
Part of:
Follow up to:
Related:
This PR add background image UI controls to top-level global styles.
TODO
Why?
Background styles can now be added to theme.json since #59354.
The styles are currently only " top-level", which means they're added to
body
selector.This PR allows users to edit these styles in the site editor.
How?
Similar to dimensions and typography panels, this PR refactors the background block supports component so that it can be shared between the site and post editors.
It moves all relevant tests and styles to the
/global-styles
directory.Testing Instructions
This is a big one, so get comfortable.
Firstly, check out this branch.
At this stage it's probably good to check if there are any regressions to background block supports. So, add a group block to a post, and make sure you can:
If that's all good, head over to the site editor.
I've been using empty theme to test. Here is some test theme.json, with a relative path to the updated theme.json schema:
Ensure that:
undefined
for site backgrounds. See table images below.Testing Instructions for Keyboard
In the global styles panel, ensure you can navigate to the "Background" item in the list to activate the background styles panel. There should be no regressions to keyboard interaction with background controls.
Screenshots or screencast
2024-03-01.14.39.23.mp4