From ad86ac31fcb7fa99ff9f4c6f6ddc55b91f9273a9 Mon Sep 17 00:00:00 2001 From: ramon Date: Fri, 5 Apr 2024 14:20:02 +1100 Subject: [PATCH 1/2] rename constant to BACKGROUND_DEFAULT_VALUES ensure that the default background size is displayed in the control --- packages/block-editor/src/hooks/background.js | 4 ++-- .../src/components/global-styles/background-panel.js | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/block-editor/src/hooks/background.js b/packages/block-editor/src/hooks/background.js index 7c8d62d5dd5a9..3d47f42645afc 100644 --- a/packages/block-editor/src/hooks/background.js +++ b/packages/block-editor/src/hooks/background.js @@ -20,7 +20,7 @@ import { export const BACKGROUND_SUPPORT_KEY = 'background'; // Initial control values where no block style is set. -const BACKGROUND_BLOCK_DEFAULT_VALUES = { +const BACKGROUND_DEFAULT_VALUES = { backgroundSize: 'cover', }; @@ -173,7 +173,7 @@ export function BackgroundImagePanel( { as={ BackgroundInspectorControl } panelId={ clientId } defaultControls={ defaultControls } - defaultValues={ BACKGROUND_BLOCK_DEFAULT_VALUES } + defaultValues={ BACKGROUND_DEFAULT_VALUES } settings={ updatedSettings } onChange={ onChange } value={ style } 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 e4760a810ecbc..cae8bdba61871 100644 --- a/packages/edit-site/src/components/global-styles/background-panel.js +++ b/packages/edit-site/src/components/global-styles/background-panel.js @@ -8,6 +8,11 @@ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; */ import { unlock } from '../../lock-unlock'; +// Initial control values where no block style is set. +const BACKGROUND_DEFAULT_VALUES = { + backgroundSize: 'auto', +}; + const { useGlobalStyle, useGlobalSetting, @@ -29,6 +34,7 @@ export default function BackgroundPanel() { value={ style } onChange={ setStyle } settings={ settings } + defaultValues={ BACKGROUND_DEFAULT_VALUES } /> ); } From 70bc802c1d531d47295255171743c5555e1146ff Mon Sep 17 00:00:00 2001 From: ramon Date: Fri, 5 Apr 2024 16:40:01 +1100 Subject: [PATCH 2/2] Tesating if `currentValueForToggle` is a good substitute for sizeValue to determine if the size control should be displayed --- .../src/components/global-styles/background-panel.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/block-editor/src/components/global-styles/background-panel.js b/packages/block-editor/src/components/global-styles/background-panel.js index 1288ff823b46c..c1354bbc4a4e1 100644 --- a/packages/block-editor/src/components/global-styles/background-panel.js +++ b/packages/block-editor/src/components/global-styles/background-panel.js @@ -492,9 +492,9 @@ function BackgroundSizeToolsPanelItem( { label={ __( 'Fixed' ) } /> - { sizeValue !== undefined && - sizeValue !== 'cover' && - sizeValue !== 'contain' ? ( + { currentValueForToggle !== undefined && + currentValueForToggle !== 'cover' && + currentValueForToggle !== 'contain' ? (