-
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: add option to remove site-wide theme background image #61998
Conversation
…-wide background image in the editor by settings the value to `background-image: none`
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. |
@@ -279,6 +281,23 @@ function BackgroundImageToolsPanelItem( { | |||
|
|||
const hasValue = hasBackgroundImageValue( style ); | |||
|
|||
const closeAndFocus = () => { |
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.
An abstraction since we need this in two places
@@ -83,6 +83,8 @@ export function hasBackgroundSizeValue( style ) { | |||
export function hasBackgroundImageValue( style ) { | |||
return ( | |||
!! style?.background?.backgroundImage?.id || | |||
// Supports url() string values in theme.json. | |||
'string' === typeof style?.background?.backgroundImage || |
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 so we can detect strings values with url()
"styles": {
"background": {
"backgroundImage": "url('https://images.pexels.com/photos/22484288/pexels-photo-22484288/free-photo-of-the-circular-stone-terraces-of-the-inca-ruins.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2')"
}
}
onRemove(); | ||
} } | ||
> | ||
{ __( 'Remove' ) } |
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 "Remove" clear enough?
It should only appear where there's a theme.json value AND there's no user style defined - basically so users can remove the default theme background image and nothing else.
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.
Yeah that's a good question. I think visually it's pretty clear when you open the dropdown by clicking on tile with the image name and thumbnail; in context "Remove" could only be related to that image. But a quick test with VoiceOver shows the experience is pretty flaky if you don't have the visual context: you tab past a menu popup button named "Background options" (this is the only clue you get that you're in a section related to background), then you tab into another menu popup button labeled with the the image file name, plus "Selected image: Untitled". That's a wider problem than this PR addresses though, so I'm not suggesting tying to solve it here 😅
Really tools panels were never accessible to begin with, which is the main issue, but perhaps for this particular instance we could improve the experience by switching the order of file name and "Selected image: Untitled", and maybe changing "Selected image" to "Site background image" (I'm not sure where the "Untitled" is coming from? but maybe we could dispense with it altogether?). But given this is an existing issue it should probably be addressed in a follow-up.
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.
Code LGTM and it's working well in testing! Plus it's a really useful enhancement, because currently there's no way of getting rid of a theme background image short of editing the theme files 😅
onRemove(); | ||
} } | ||
> | ||
{ __( 'Remove' ) } |
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.
Yeah that's a good question. I think visually it's pretty clear when you open the dropdown by clicking on tile with the image name and thumbnail; in context "Remove" could only be related to that image. But a quick test with VoiceOver shows the experience is pretty flaky if you don't have the visual context: you tab past a menu popup button named "Background options" (this is the only clue you get that you're in a section related to background), then you tab into another menu popup button labeled with the the image file name, plus "Selected image: Untitled". That's a wider problem than this PR addresses though, so I'm not suggesting tying to solve it here 😅
Really tools panels were never accessible to begin with, which is the main issue, but perhaps for this particular instance we could improve the experience by switching the order of file name and "Selected image: Untitled", and maybe changing "Selected image" to "Site background image" (I'm not sure where the "Untitled" is coming from? but maybe we could dispense with it altogether?). But given this is an existing issue it should probably be addressed in a follow-up.
Thanks for the feedback and testing @tellthemachines
Good idea. "untitled" is the fallback where the image has no title. I have a tweak PR going so I can update that over there. Cheers! |
Good starting point, I'm assuming we can also reset it using the toolspanel mechanism as is the case for the group bg option? There may be a larger question, across all design-tools and perhaps related to the inheritance visualization work, to improve how items are generally reset to their theme.json definitions. It's ultimately about user customizations. The curious piece here is that you may be resetting an image, and are then surprised to still see an image, expecting there to be no image. The closest equivalent to mimic is likely going to be having an explicit "no background image" option, similar to how we have explicit text-decoration definitions, or explicit "no color" definitions. |
If the background image is defined by the theme (if comes from the theme.json) then the tools panel reset shouldn't remove it, right? At least I always assumed that "reset" means returning to whatever the theme defaults are. |
Global styles should always show all tools in a tools panel, and yes, clicking reset should reset to "default", which would be whatever default theme.json provides. So I'm not suggesting an action item, I'm mainly thinking through what the longer term solution is for adding an explicit "none" option background images, similar to explicit "no background color" or explicit "no text-decoration" options, for the case where you want to unset a default. What we have in this branch is good, just wondering if there are clearer labels: "remove" and "reset" are a bit confusing. I wonder if "Reset" and "No background image" would be clearer? |
…-wide background image in the editor by settings the value to `background-image: none` (WordPress#61998) Co-authored-by: ramonjd <ramonopoly@git.wordpress.org> Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>
…-wide background image in the editor by settings the value to `background-image: none` (WordPress#61998) Co-authored-by: ramonjd <ramonopoly@git.wordpress.org> Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>
Dev Note 📓
#59354 (comment)
What?
Part of:
Hello.
This PR implements @andrewserong's idea and adds functionality to remove a theme's default, site-wide background image in the editor.
See: #61271 (comment)
Why?
Check it out:
2024-05-27.12.00.28.mp4
There's no way to remove a background image if it's been defined in theme.json.
How?
By adding a "Remove" option to the image dropdown that sets the value of
background.backgroundImage
to"none"
, when:Testing Instructions
background-image
should be"none"
.Here's some test theme.json!
Screenshots or screencast
2024-05-27.11.50.07.mp4