-
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
Try fixing captions on resized images #6496
Changes from 4 commits
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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
|
@@ -165,6 +170,10 @@ export const settings = { | |
save( { attributes } ) { | ||
const { url, alt, caption, align, href, width, height, id } = attributes; | ||
|
||
const classes = classnames( align ? `align${ align }` : null, { | ||
'is-resized': !! width || !! height, | ||
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. Just curious, could we remove the need for this class with the following? img[height],
img[width] {
...
} 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. And if caption needs targeting. img[height] + figcaption,
img[width] + figcaption {
...
} 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. Sadly, we cannot, because 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. This change needs a 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. ^ Yeah this is why I was wondering if we could avoid introducing new attributes, but ok if really needed! :) 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. Added a deprecated version in 68b40e5. Did I do that right? To clarify what happens — if the figure is as wide as the main content, it needs Should the class be called "is-resized" for that, or can we think of something better? 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. Minor: |
||
} ); | ||
|
||
const image = ( | ||
<img | ||
src={ url } | ||
|
@@ -176,7 +185,7 @@ export const settings = { | |
); | ||
|
||
return ( | ||
<figure className={ align ? `align${ align }` : null }> | ||
<figure className={ classes }> | ||
{ href ? <a href={ href }>{ image }</a> : image } | ||
{ caption && caption.length > 0 && <RichText.Content tagName="figcaption" value={ caption } /> } | ||
</figure> | ||
|
@@ -190,6 +199,9 @@ export const settings = { | |
const { url, alt, caption, align, href, width, height } = attributes; | ||
const extraImageProps = width || height ? { width, height } : {}; | ||
const image = <img src={ url } alt={ alt } { ...extraImageProps } />; | ||
const classes = classnames( align ? `align${ align }` : null, { | ||
'is-resized': !! width || !! height, | ||
} ); | ||
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 don't understand this change? I think the deprecated versions shouldn't be updated once they land. I think what we need to do here is to add a new 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. Sounds good to me. Can you help me with this? Feel free to push directly 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. Sounds good to me. Can you help me with this? Feel free to push directly |
||
|
||
let figureStyle = {}; | ||
|
||
|
@@ -200,7 +212,7 @@ export const settings = { | |
} | ||
|
||
return ( | ||
<figure className={ align ? `align${ align }` : null } style={ figureStyle }> | ||
<figure className={ classes } style={ figureStyle }> | ||
{ href ? <a href={ href }>{ image }</a> : image } | ||
{ caption && caption.length > 0 && <RichText.Content tagName="figcaption" value={ caption } /> } | ||
</figure> | ||
|
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.
Minor: Good use case for
classnames
object format is to inverse this, so you don't need to assign a fallbacknull
value to be omitted: