Skip to content

Commit

Permalink
Background image: size controls should show when an image is set (#61388
Browse files Browse the repository at this point in the history
)

* In the site editor, show the background size panel if a value is present, just like block styles.

* Show size controls by default

* Revert inherited style check

Co-authored-by: ramonjd <[email protected]>
Co-authored-by: andrewserong <[email protected]>
Co-authored-by: jameskoster <[email protected]>
  • Loading branch information
4 people authored and pull[bot] committed Oct 23, 2024
1 parent a3b385e commit 3085263
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ const {
BackgroundPanel: StylesBackgroundPanel,
} = unlock( blockEditorPrivateApis );

/**
* Checks if there is a current value in the background image block support
* attributes.
*
* @param {Object} style Style attribute.
* @return {boolean} Whether the block has a background image value set.
*/
export function hasBackgroundImageValue( style ) {
return (
!! style?.background?.backgroundImage?.id ||
!! style?.background?.backgroundImage?.url ||
typeof style?.background?.backgroundImage === 'string'
);
}

export default function BackgroundPanel() {
const [ style ] = useGlobalStyle( '', undefined, 'user', {
shouldDecodeEncode: false,
Expand All @@ -32,8 +47,8 @@ export default function BackgroundPanel() {
const defaultControls = {
backgroundImage: true,
backgroundSize:
!! style?.background?.backgroundImage &&
!! inheritedStyle?.background?.backgroundImage,
hasBackgroundImageValue( style ) ||
hasBackgroundImageValue( inheritedStyle ),
};

return (
Expand Down

0 comments on commit 3085263

Please sign in to comment.