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

Test caption length when considering to show editable #684

Merged
merged 4 commits into from
May 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions blocks/library/embed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ registerBlock( 'core/embed', {
<div className="iframe-overlay">
<iframe src={ url } title={ title } />
</div>
{ caption || !! focus ? (
{ ( caption && caption.length > 0 ) || !! focus ? (
<Editable
tagName="figcaption"
placeholder={ wp.i18n.__( 'Write caption…' ) }
Expand All @@ -67,7 +67,7 @@ registerBlock( 'core/embed', {
const { url, title, caption } = attributes;
const iframe = <iframe src={ url } title={ title } />;

if ( ! caption ) {
if ( ! caption || ! caption.length ) {
return iframe;
}

Expand Down
4 changes: 2 additions & 2 deletions blocks/library/image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ registerBlock( 'core/image', {
return (
<figure className="blocks-image">
<img src={ url } alt={ alt } />
{ caption || !! focus ? (
{ ( caption && caption.length > 0 ) || !! focus ? (
<Editable
tagName="figcaption"
placeholder={ wp.i18n.__( 'Write caption…' ) }
Expand All @@ -113,7 +113,7 @@ registerBlock( 'core/image', {
const { url, alt, caption, align = 'none' } = attributes;
const img = <img src={ url } alt={ alt } className={ `align${ align }` } />;

if ( ! caption ) {
if ( ! caption || ! caption.length ) {
return img;
}

Expand Down
8 changes: 5 additions & 3 deletions blocks/library/quote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ registerBlock( 'core/quote', {
onMerge={ mergeWithPrevious }
showAlignments
/>
{ ( citation || !! focus ) && (
{ ( ( citation && citation.length > 0 ) || !! focus ) && (
Copy link
Member Author

Choose a reason for hiding this comment

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

Preempting a concern here: Yes, this is ugly. Rather than extract to a separate variable, I think we should acknowledge its ugliness and try to avoid it altogether by providing default values for children. This should be addressed separately.

<Editable
tagName="footer"
value={ citation }
Expand All @@ -143,10 +143,12 @@ registerBlock( 'core/quote', {

return (
<blockquote className={ `blocks-quote-style-${ style }` }>
{ value && wp.element.Children.map( value, ( paragraph, i ) => (
{ value && value.map( ( paragraph, i ) => (
<p key={ i }>{ paragraph }</p>
) ) }
<footer>{ citation }</footer>
{ citation && citation.length > 0 && (
<footer>{ citation }</footer>
) }
</blockquote>
);
}
Expand Down
4 changes: 2 additions & 2 deletions post-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ window._wpGutenbergPost = {
'<!-- /wp:core/text -->',

'<!-- wp:core/image align="center" -->',
'<figure><img src="https://cldup.com/E4PzNdrFSQ.jpg" class="aligncenter"/><figcaption><p>Give it a try. Press the &quot;really wide&quot; button on the image toolbar.</p></figcaption></figure>',
'<figure><img src="https://cldup.com/E4PzNdrFSQ.jpg" class="aligncenter"/><figcaption>Give it a try. Press the &quot;really wide&quot; button on the image toolbar.</figcaption></figure>',
'<!-- /wp:core/image -->',

'<!-- wp:core/text -->',
'<p>Try selecting and removing or editing the caption, now you don\'t have to be careful about selecting the image or other text by mistake and ruining the presentation.</p>',
'<!-- /wp:core/text -->',

'<!-- wp:core/embed url="https://www.youtube.com/watch?v=Nl6U7UotA-M" -->',
'<figure><iframe width="560" height="315" src="//www.youtube.com/embed/Nl6U7UotA-M" frameborder="0" allowfullscreen></iframe><figcaption><p>State of the Word 2016</p></figcaption></figure>',
'<figure><iframe width="560" height="315" src="//www.youtube.com/embed/Nl6U7UotA-M" frameborder="0" allowfullscreen></iframe><figcaption>State of the Word 2016</figcaption></figure>',
'<!-- /wp:core/embed -->',

'<!-- wp:core/heading -->',
Expand Down