Skip to content

Commit

Permalink
background-size auto is the same as no background-size
Browse files Browse the repository at this point in the history
bad rebase
  • Loading branch information
ramonjd committed Mar 20, 2024
1 parent 011c77d commit 7ab18c8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
16 changes: 8 additions & 8 deletions docs/reference-guides/block-api/block-supports.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ When a background image is selected, the image data is stored in the `style.back
When a background images is selected and its position or size are changed, the background-position is stored in the `style.background.backgroundPosition` and its background-size in `style.background.backgroundSize` attribute.

- `style`: an attribute of `object` type with no default assigned. This is added when `backgroundImage` or `backgroundSize` support is declared. It stores the custom values set by the user.
- `background`: an attribute of `object` type.
- `backgroundImage`: an attribute of `object` type, containing information about the selected image
- `background`: an attribute of `object` type.
- `backgroundImage`: an attribute of `object` type, containing information about the selected image
- `url`: type `string`, URL to the image
- `id`: type `int`, media attachment ID
- `source`: type `string`, at the moment the only value is `file`
- `title`: type `string`, title of the media attachment
- `backgroundPosition`: an attribute of `string` type, defining the background images position, selected by FocalPointPicker and used in CSS as the [`background-position`](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position) value.
- `title`: type `string`, title of the media attachment
- `backgroundPosition`: an attribute of `string` type, defining the background images position, selected by FocalPointPicker and used in CSS as the [`background-position`](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position) value.
- `backgroundSize`: an attribute of `string` type. defining the CSS [`background-size`](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size) value.

The block can apply a default background image, position and size by specifying its own attribute with a default. For example:
Expand Down Expand Up @@ -484,10 +484,10 @@ When the block declares support for `color.link`, the attributes definition is e
color: {
text: 'var:preset|color|contrast',
},
":hover": {
color: {
text: "#000000"
}
":hover": {
color: {
text: "#000000"
}
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions lib/block-supports/background.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ function gutenberg_register_background_support( $block_type ) {
* @return array Style engine array of CSS string and style declarations.
*/
function gutenberg_get_background_support_styles( $background_styles = array() ) {
$background_styles['backgroundSize'] = ! empty( $background_styles['backgroundSize'] ) ? $background_styles['backgroundSize'] : 'auto';

return gutenberg_style_engine_get_styles( array( 'background' => $background_styles ) );
}

Expand Down
6 changes: 6 additions & 0 deletions packages/block-editor/src/hooks/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -641,3 +641,9 @@ export function BackgroundImagePanel( props ) {
</InspectorControls>
);
}

export default {
useBlockProps,
attributeKeys: [ 'style' ],
hasSupport: hasBackgroundSupport,
};
1 change: 1 addition & 0 deletions packages/block-editor/src/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ createBlockEditFilter(
);
createBlockListBlockFilter( [
align,
background,
style,
color,
dimensions,
Expand Down
4 changes: 2 additions & 2 deletions phpunit/block-supports/background-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,13 @@ public function data_get_background_support_styles() {
'source' => 'file',
),
),
'expected_css' => "background-image:url('https://example.com/image.jpg');background-size:auto;",
'expected_css' => "background-image:url('https://example.com/image.jpg');",
),
'css generated where backgroundImage is a string' => array(
'background_style' => array(
'backgroundImage' => "url('https://example.com/image.jpg')",
),
'expected_css' => "background-image:url('https://example.com/image.jpg');background-size:auto;",
'expected_css' => "background-image:url('https://example.com/image.jpg');",
),
'css generated with escaped URL' => array(
'background_style' => array(
Expand Down

0 comments on commit 7ab18c8

Please sign in to comment.