Skip to content

Commit

Permalink
Test caption length when considering to show editable (#684)
Browse files Browse the repository at this point in the history
* Remove paragraphs from captioned content

* Test caption length when considering to show editable

* Treat serialized content as array

* Test truthiness of children before assuming property

Can be undefined for new block. We may want to look to provide default,
but for now simply test truthiness.
  • Loading branch information
aduth authored and mtias committed May 8, 2017
1 parent a72b370 commit e4d749a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
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 ) && (
<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

0 comments on commit e4d749a

Please sign in to comment.