-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Media & Text block should not use background image (Closes #52789) #58514
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ import { useInnerBlocksProps, useBlockProps } from '@wordpress/block-editor'; | |
/** | ||
* Internal dependencies | ||
*/ | ||
import { imageFillStyles } from './media-container'; | ||
import { focalPosition } from './media-container'; | ||
import { DEFAULT_MEDIA_SIZE_SLUG } from './constants'; | ||
|
||
const DEFAULT_MEDIA_WIDTH = 50; | ||
|
@@ -42,10 +42,17 @@ export default function save( { attributes } ) { | |
[ `size-${ mediaSizeSlug }` ]: mediaId && mediaType === 'image', | ||
} ); | ||
|
||
const objectPosition = | ||
// prettier-ignore | ||
focalPoint | ||
? focalPosition(focalPoint) | ||
: undefined; | ||
Comment on lines
+47
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It appears that previously even if |
||
|
||
let image = ( | ||
<img | ||
src={ mediaUrl } | ||
alt={ mediaAlt } | ||
style={ { objectPosition } } | ||
className={ imageClasses || null } | ||
/> | ||
); | ||
|
@@ -56,6 +63,7 @@ export default function save( { attributes } ) { | |
className={ linkClass } | ||
href={ href } | ||
target={ linkTarget } | ||
style={ { objectPosition } } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There’s no need to add |
||
rel={ newRel } | ||
> | ||
{ image } | ||
|
@@ -65,17 +73,16 @@ export default function save( { attributes } ) { | |
|
||
const mediaTypeRenders = { | ||
image: () => image, | ||
video: () => <video controls src={ mediaUrl } />, | ||
video: () => ( | ||
<video controls src={ mediaUrl } style={ { objectPosition } } /> | ||
), | ||
}; | ||
const className = classnames( { | ||
'has-media-on-the-right': 'right' === mediaPosition, | ||
'is-stacked-on-mobile': isStackedOnMobile, | ||
[ `is-vertically-aligned-${ verticalAlignment }` ]: verticalAlignment, | ||
'is-image-fill': imageFill, | ||
} ); | ||
const backgroundStyles = imageFill | ||
? imageFillStyles( mediaUrl, focalPoint ) | ||
: {}; | ||
|
||
let gridTemplateColumns; | ||
if ( mediaWidth !== DEFAULT_MEDIA_WIDTH ) { | ||
|
@@ -96,21 +103,15 @@ export default function save( { attributes } ) { | |
className: 'wp-block-media-text__content', | ||
} ) } | ||
/> | ||
<figure | ||
className="wp-block-media-text__media" | ||
style={ backgroundStyles } | ||
> | ||
<figure className="wp-block-media-text__media"> | ||
{ ( mediaTypeRenders[ mediaType ] || noop )() } | ||
</figure> | ||
</div> | ||
); | ||
} | ||
return ( | ||
<div { ...useBlockProps.save( { className, style } ) }> | ||
<figure | ||
className="wp-block-media-text__media" | ||
style={ backgroundStyles } | ||
> | ||
<figure className="wp-block-media-text__media"> | ||
{ ( mediaTypeRenders[ mediaType ] || noop )() } | ||
</figure> | ||
<div | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ | |
grid-row: 1; | ||
/*!rtl:end:ignore*/ | ||
margin: 0; | ||
position: relative; | ||
} | ||
|
||
.wp-block-media-text .wp-block-media-text__content { | ||
|
@@ -86,16 +87,23 @@ | |
height: 100%; | ||
} | ||
|
||
.wp-block-media-text.is-image-fill .wp-block-media-text__media img { | ||
// The image is visually hidden but accessible to assistive technologies. | ||
position: absolute; | ||
width: 1px; | ||
height: 1px; | ||
.wp-block-media-text.is-image-fill .wp-block-media-text__media img, | ||
.wp-block-media-text.is-image-fill .wp-block-media-text__media video { | ||
border: none; | ||
bottom: 0; | ||
box-shadow: none; | ||
height: 100%; | ||
left: 0; | ||
margin: 0; | ||
max-height: none; | ||
max-width: none; | ||
object-fit: cover; | ||
outline: none; | ||
Comment on lines
+92
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wary of adding more styles here than strictly necessary. In particular |
||
padding: 0; | ||
margin: -1px; | ||
overflow: hidden; | ||
clip: rect(0, 0, 0, 0); | ||
border: 0; | ||
position: absolute; | ||
right: 0; | ||
top: 0; | ||
Comment on lines
+104
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I'd opt to use |
||
width: 100%; | ||
Comment on lines
+90
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here |
||
} | ||
/* | ||
* Here we here not able to use a mobile first CSS approach. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having both
imageFillStyles
and this new function seems like clutter. PreviouslyimageFillStyles
was used in a two places and still could be. Or alternatively,focalPosition
could replace it in both those places. I’d prefer using one or the other and not both.