Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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