Skip to content

Commit

Permalink
Background image: display default background size value in global sty…
Browse files Browse the repository at this point in the history
…les (#60490)

* rename constant to BACKGROUND_DEFAULT_VALUES
ensure that the default background size is displayed in the control

* Tesating if `currentValueForToggle` is a good substitute for sizeValue to determine if the size control should be displayed

Co-authored-by: ramonjd <[email protected]>
Co-authored-by: andrewserong <[email protected]>
Co-authored-by: jameskoster <[email protected]>
  • Loading branch information
4 people authored Apr 8, 2024
1 parent d6a9db5 commit e9edf65
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,9 @@ function BackgroundSizeToolsPanelItem( {
label={ __( 'Fixed' ) }
/>
</ToggleGroupControl>
{ sizeValue !== undefined &&
sizeValue !== 'cover' &&
sizeValue !== 'contain' ? (
{ currentValueForToggle !== undefined &&
currentValueForToggle !== 'cover' &&
currentValueForToggle !== 'contain' ? (
<UnitControl
size={ '__unstable-large' }
onChange={ updateBackgroundSize }
Expand Down
4 changes: 2 additions & 2 deletions packages/block-editor/src/hooks/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};

Expand Down Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -29,6 +34,7 @@ export default function BackgroundPanel() {
value={ style }
onChange={ setStyle }
settings={ settings }
defaultValues={ BACKGROUND_DEFAULT_VALUES }
/>
);
}

0 comments on commit e9edf65

Please sign in to comment.