Skip to content

Commit

Permalink
add scale if height is set
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed May 10, 2021
1 parent d706e84 commit 2c4edcc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const DimensionControls = ( {
attributes: { width, height, scale },
setAttributes,
} ) => {
const dimensionsAreSet = width && height;
const onDimensionChange = ( dimension, nextValue ) => {
setAttributes( {
[ dimension ]: parseFloat( nextValue ) < 0 ? '0' : nextValue,
Expand Down Expand Up @@ -92,7 +91,7 @@ const DimensionControls = ( {
/>
</FlexItem>
</Flex>
{ dimensionsAreSet && (
{ !! height && (
<>
<BaseControl
aria-label={ scaleLabel }
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/post-featured-image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function PostFeaturedImageDisplay( {
<img
src={ media.source_url }
alt={ media.alt_text || __( 'Featured image' ) }
style={ { height, objectFit: height && width && scale } }
style={ { height, objectFit: height && scale } }
/>
);
}
Expand Down
11 changes: 4 additions & 7 deletions packages/block-library/src/post-featured-image/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,14 @@ function render_block_core_post_featured_image( $attributes, $content, $block )
$wrapper_attributes = get_block_wrapper_attributes( array( 'style' => "width:{$attributes['width']};" ) );
}

$image_styles = '';
if ( $has_height ) {
$image_styles = "height:{$attributes['height']};";
}
if ( $has_height && $has_width && ! empty( $attributes['scale'] ) ) {
$image_styles .= "object-fit:{$attributes['scale']};";
}

if ( $image_styles ) {
if ( ! empty( $attributes['scale'] ) ) {
$image_styles .= "object-fit:{$attributes['scale']};";
}
$featured_image = str_replace( 'src=', "style='$image_styles' src=", $featured_image );
}

return "<figure $wrapper_attributes>$featured_image</figure>";
}

Expand Down

0 comments on commit 2c4edcc

Please sign in to comment.