From 00b579d0472234630412212a143d1c414d14c45c Mon Sep 17 00:00:00 2001 From: ramon Date: Wed, 8 May 2024 11:59:47 +1000 Subject: [PATCH] Show size controls by default --- .../global-styles/background-panel.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/edit-site/src/components/global-styles/background-panel.js b/packages/edit-site/src/components/global-styles/background-panel.js index 798e4bfe610f3..65dd9738b2b4f 100644 --- a/packages/edit-site/src/components/global-styles/background-panel.js +++ b/packages/edit-site/src/components/global-styles/background-panel.js @@ -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, @@ -31,7 +46,9 @@ export default function BackgroundPanel() { const defaultControls = { backgroundImage: true, - backgroundSize: false, + backgroundSize: + hasBackgroundImageValue( style ) || + hasBackgroundImageValue( inheritedStyle ), }; return (