-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 || | ||
!! style?.background?.backgroundImage?.url | ||
); | ||
} | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. An abstraction since we need this in two places |
||
const [ toggleButton ] = focus.tabbable.find( | ||
replaceContainerRef.current | ||
); | ||
// Focus the toggle button and close the dropdown menu. | ||
// This ensures similar behaviour as to selecting an image, where the dropdown is | ||
// closed and focus is redirected to the dropdown toggle button. | ||
toggleButton?.focus(); | ||
toggleButton?.click(); | ||
}; | ||
|
||
const onRemove = () => | ||
onChange( | ||
setImmutably( style, [ 'background', 'backgroundImage' ], 'none' ) | ||
); | ||
const canRemove = ! hasValue && hasBackgroundImageValue( inheritedValue ); | ||
|
||
return ( | ||
<ToolsPanelItem | ||
className="single-column" | ||
|
@@ -311,17 +330,20 @@ function BackgroundImageToolsPanelItem( { | |
} | ||
variant="secondary" | ||
> | ||
{ canRemove && ( | ||
<MenuItem | ||
onClick={ () => { | ||
closeAndFocus(); | ||
onRemove(); | ||
} } | ||
> | ||
{ __( 'Remove' ) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. |
||
</MenuItem> | ||
) } | ||
{ hasValue && ( | ||
<MenuItem | ||
onClick={ () => { | ||
const [ toggleButton ] = focus.tabbable.find( | ||
replaceContainerRef.current | ||
); | ||
// Focus the toggle button and close the dropdown menu. | ||
// This ensures similar behaviour as to selecting an image, where the dropdown is | ||
// closed and focus is redirected to the dropdown toggle button. | ||
toggleButton?.focus(); | ||
toggleButton?.click(); | ||
closeAndFocus(); | ||
resetBackgroundImage(); | ||
} } | ||
> | ||
|
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()