Skip to content

Commit

Permalink
Fix: Featured image block contains invalid HTML (#17754)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta authored Oct 10, 2019
1 parent 780860f commit 401ed23
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/components/src/responsive-wrapper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,26 @@ import classnames from 'classnames';
*/
import { cloneElement, Children } from '@wordpress/element';

function ResponsiveWrapper( { naturalWidth, naturalHeight, children } ) {
function ResponsiveWrapper( {
naturalWidth,
naturalHeight,
children,
isInline = false,
} ) {
if ( Children.count( children ) !== 1 ) {
return null;
}
const imageStyle = {
paddingBottom: ( naturalHeight / naturalWidth * 100 ) + '%',
};
const TagName = isInline ? 'span' : 'div';
return (
<div className="components-responsive-wrapper">
<div style={ imageStyle } />
<TagName className="components-responsive-wrapper">
<TagName style={ imageStyle } />
{ cloneElement( children, {
className: classnames( 'components-responsive-wrapper__content', children.props.className ),
} ) }
</div>
</TagName>
);
}

Expand Down
4 changes: 4 additions & 0 deletions packages/components/src/responsive-wrapper/style.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
.components-responsive-wrapper {
position: relative;
max-width: 100%;
&,
& > span {
display: block;
}
}

.components-responsive-wrapper__content {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function PostFeaturedImage( { currentPostId, featuredImageId, onUpdateImage, onR
<ResponsiveWrapper
naturalWidth={ mediaWidth }
naturalHeight={ mediaHeight }
isInline
>
<img src={ mediaSourceUrl } alt="" />
</ResponsiveWrapper>
Expand Down

0 comments on commit 401ed23

Please sign in to comment.