Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background image: display default background size value in global styles #60490

Merged
Merged
Show file tree
Hide file tree
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 @@ -492,9 +492,9 @@ function BackgroundSizeToolsPanelItem( {
label={ __( 'Fixed' ) }
/>
</ToggleGroupControl>
{ sizeValue !== undefined &&
sizeValue !== 'cover' &&
sizeValue !== 'contain' ? (
{ currentValueForToggle !== undefined &&
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's working nicely for me!

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',
Copy link
Member Author

@ramonjd ramonjd Apr 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is useful regardless of the defaults we choose.

See:

We want to display the default value in the control.

background-size is technically not set at all, but the effect is the same as "Fixed" which is the label for "background-size: auto"

};

const {
useGlobalStyle,
useGlobalSetting,
Expand All @@ -29,6 +34,7 @@ export default function BackgroundPanel() {
value={ style }
onChange={ setStyle }
settings={ settings }
defaultValues={ BACKGROUND_DEFAULT_VALUES }
/>
);
}
Loading