-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Background image: explicitly set background repeat value in user styles #61526
Conversation
Fix edge case in which theme.json defines a backgroundSize value of 'cover' and a backgroundRepeat value. If a user backgroundSize is set, ignore the inherited backgroundRepeat value as style?.background?.backgroundRepeat is deliberately set to undefined in updateBackgroundSize().
Roll back previous fix, and explicitly set backgroundRepeat to "repeat", because it seems as if it's being overwritten by merging styles (undefined values are stripped)
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. |
@@ -439,7 +439,7 @@ function BackgroundSizeToolsPanelItem( { | |||
setImmutably( | |||
style, | |||
[ 'background', 'backgroundRepeat' ], | |||
repeatCheckedValue === true ? 'no-repeat' : undefined | |||
repeatCheckedValue === true ? 'no-repeat' : 'repeat' |
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.
This is the magic
@@ -51,6 +51,11 @@ export const __EXPERIMENTAL_STYLE_PROPERTY = { | |||
support: [ 'background', 'backgroundSize' ], | |||
useEngine: true, | |||
}, | |||
backgroundPosition: { |
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.
Just adding this here for completeness
@@ -39,7 +39,7 @@ const backgroundImage = { | |||
}; | |||
|
|||
const backgroundPosition = { | |||
name: 'backgroundRepeat', | |||
name: 'backgroundPosition', |
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 might have just been a typo from #58592
Size Change: +19 B (0%) Total Size: 1.74 MB
ℹ️ View Unchanged
|
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.
Great catch, thanks for the detailed testing instructions and for fixing up the typo, too!
This is nesting nicely for each of the different permutations in site wide background images, while not causing any issues at the block level when adjusting for a Group block.
LGTM! 🚀
What?
Explicitly sets a "repeat" value for user background repeat styles.
Also adds/fixes some missing styles properties.
Why?
This mainly fixes an edge case where theme.json defines background size of "cover" and "no-repeat".
Now, these two properties don't really work together visually, but they're valid CSS.
When setting
backgroundRepeat
toundefined
in user styles, it seems as if the theme.json value will take precedence during the global styles config merge of the two styles objects (theme.json and user).This is of course undesirable as the user styles should take precedence, but since it we set it to undefined Gutenberg will go for the truthy value when merging.
How?
The only fix I could come up with was setting the string value of "repeat" to ensure the user styles take precedence.
Testing Instructions
Check that the global styles background image controls are still usable in the site editor with the follow theme.json.
All other manifestations should work as expected, and their values should show up in the global styles background image controls, e.g.,
Screenshots or screencast
Before
2024-05-09.22.27.49.mp4
After
2024-05-09.22.15.35.mp4