Skip to content
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

Image: do not display empty caption. #674

Closed
wants to merge 1 commit into from

Conversation

mtias
Copy link
Member

@mtias mtias commented May 5, 2017

Fixes #673

@mtias mtias added the [Feature] Blocks Overall functionality of blocks label May 5, 2017
@mtias mtias requested review from youknowriad and aduth May 5, 2017 12:32
@@ -95,7 +95,7 @@ registerBlock( 'core/image', {
return (
<figure className="blocks-image">
<img src={ url } alt={ alt } />
{ caption || !! focus ? (
{ caption.length || !! focus ? (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

caption && caption.length maybe. I think caption could be undefined

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also check in save?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the ! caption check is probably not enough since the caption shape changed.

! caption || ! caption.length to match the edit?

@mtias mtias force-pushed the fix/do-not-display-empty-caption branch from ac61af1 to 27c97a9 Compare May 5, 2017 12:43
@mtias
Copy link
Member Author

mtias commented May 5, 2017

If you add some text to an empty caption, then remove it, the check for length fails. Seems we need to check for children in props as well:

image

@mtias mtias force-pushed the fix/do-not-display-empty-caption branch from 27c97a9 to 9c8a9ac Compare May 5, 2017 13:02
@aduth
Copy link
Member

aduth commented May 5, 2017

Oops, I must have overlooked this and separately put together #684.

However, the changes there are more complete:

  • Removes invalid markup from post-content.js
  • Fixes quote and embed blocks which suffer from same issue
  • Doesn't care to test undefined
    • When can caption be undefined? If there is, we should see if we can eliminate it. I'm on a crusade to simplify element content to always be an array.

I would need to incorporate the save fix though.

@aduth
Copy link
Member

aduth commented May 5, 2017

When can caption be undefined?

Okay, I see now it's mainly with newly created blocks. I'm wondering if it's worthwhile to always default these to an empty array so we don't have to worry about whether it's undefined or an array.

@aduth
Copy link
Member

aduth commented May 5, 2017

Sorry to hijack this, but I'm going to close in favor of #684.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants