Skip to content

Commit

Permalink
Revert "Image Block: add caption field to placeholder (#22295)" (#23027)
Browse files Browse the repository at this point in the history
This reverts commit 2f1a8e7.
  • Loading branch information
ellatrix authored and oandregal committed Jun 9, 2020
1 parent 5aae0c2 commit cbd8168
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 47 deletions.
48 changes: 21 additions & 27 deletions packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export function ImageEdit( {
alt: undefined,
id: undefined,
title: undefined,
caption: undefined,
} );
return;
}
Expand All @@ -175,9 +176,9 @@ export function ImageEdit( {
}
}

// If a caption text was meanwhile written by the user, make sure the
// text is not overwritten by another caption.
if ( caption ) {
// If a caption text was meanwhile written by the user,
// make sure the text is not overwritten by empty captions.
if ( caption && ! get( mediaAttributes, [ 'caption' ] ) ) {
mediaAttributes = omit( mediaAttributes, [ 'caption' ] );
}

Expand Down Expand Up @@ -403,33 +404,11 @@ export function ImageEdit( {
imageHeight,
} = useImageSize( ref, url, [ align ] );

let captionField;

if ( ! RichText.isEmpty( caption ) || isSelected ) {
captionField = (
<RichText
tagName="figcaption"
placeholder={ __( 'Write caption…' ) }
value={ caption }
unstableOnFocus={ onFocusCaption }
onChange={ ( value ) => setAttributes( { caption: value } ) }
isSelected={ captionFocused }
inlineToolbar
__unstableOnSplitAtEnd={ () =>
insertBlocksAfter( createBlock( 'core/paragraph' ) )
}
/>
);
}

if ( ! url ) {
return (
<>
{ controls }
<Block.figure>
{ mediaPlaceholder }
{ captionField }
</Block.figure>
<Block.div>{ mediaPlaceholder }</Block.div>
</>
);
}
Expand Down Expand Up @@ -617,7 +596,22 @@ export function ImageEdit( {
{ controls }
<Block.figure ref={ ref } className={ classes }>
{ img }
{ captionField }
{ ( ! RichText.isEmpty( caption ) || isSelected ) && (
<RichText
tagName="figcaption"
placeholder={ __( 'Write caption…' ) }
value={ caption }
unstableOnFocus={ onFocusCaption }
onChange={ ( value ) =>
setAttributes( { caption: value } )
}
isSelected={ captionFocused }
inlineToolbar
__unstableOnSplitAtEnd={ () =>
insertBlocksAfter( createBlock( 'core/paragraph' ) )
}
/>
) }
{ mediaPlaceholder }
</Block.figure>
</>
Expand Down
11 changes: 0 additions & 11 deletions packages/e2e-tests/specs/editor/blocks/image.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,4 @@ describe( 'Image', () => {
await page.evaluate( () => document.activeElement.innerHTML )
).toBe( '12' );
} );

it( 'should keep caption after upload', async () => {
await insertBlock( 'Image' );
await page.keyboard.type( '1' );
const filename1 = await upload( '.wp-block-image input[type="file"]' );

const regex = new RegExp(
`<!-- wp:image {"id":\\d+,"sizeSlug":"large"} -->\\s*<figure class="wp-block-image size-large"><img src="[^"]+\\/${ filename1 }\\.png" alt="" class="wp-image-\\d+"/><figcaption>1</figcaption></figure>\\s*<!-- \\/wp:image -->`
);
expect( await getEditedPostContent() ).toMatch( regex );
} );
} );
3 changes: 0 additions & 3 deletions packages/e2e-tests/specs/editor/plugins/templates.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ describe( 'templates', () => {
// re-added after saving and reloading the editor.
await page.click( '.editor-post-title__input' );
await page.keyboard.press( 'ArrowDown' );
await pressKeyWithModifier( 'shift', 'Tab' );
await page.keyboard.press( 'Backspace' );
await saveDraft();
await page.reload();
Expand All @@ -50,7 +49,6 @@ describe( 'templates', () => {
// re-added after saving and reloading the editor.
await page.type( '.editor-post-title__input', 'My Empty Book' );
await page.keyboard.press( 'ArrowDown' );
await pressKeyWithModifier( 'shift', 'Tab' );
await pressKeyWithModifier( 'primary', 'A' );
await page.keyboard.press( 'Backspace' );
await saveDraft();
Expand Down Expand Up @@ -102,7 +100,6 @@ describe( 'templates', () => {
await page.type( '.editor-post-title__input', 'My Image Format' );
await clickBlockAppender();
await page.keyboard.press( 'Backspace' );
await pressKeyWithModifier( 'shift', 'Tab' );
await page.keyboard.press( 'Backspace' );
await saveDraft();
await page.reload();
Expand Down
2 changes: 0 additions & 2 deletions packages/e2e-tests/specs/editor/various/adding-blocks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
pressKeyTimes,
setBrowserViewport,
closeGlobalBlockInserter,
pressKeyWithModifier,
} from '@wordpress/e2e-test-utils';

/** @typedef {import('puppeteer').ElementHandle} ElementHandle */
Expand Down Expand Up @@ -67,7 +66,6 @@ describe( 'adding blocks', () => {
await page.keyboard.press( 'Enter' );
expect( await getEditedPostContent() ).toMatchSnapshot();
await page.keyboard.press( 'Backspace' );
await pressKeyWithModifier( 'shift', 'Tab' );
await page.keyboard.press( 'Backspace' );
expect( await getEditedPostContent() ).toMatchSnapshot();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ describe( 'block deletion -', () => {
await page.click(
'.wp-block[data-type="core/image"] .components-placeholder__label'
);
await page.click(
'.wp-block[data-type="core/image"] .components-placeholder__label'
);
await page.keyboard.press( 'Backspace' );

expect( await getEditedPostContent() ).toMatchSnapshot();
Expand Down Expand Up @@ -199,7 +196,6 @@ describe( 'deleting all blocks', () => {

// Add and remove a block.
await insertBlock( 'Image' );
await pressKeyWithModifier( 'shift', 'Tab' );
await page.keyboard.press( 'Backspace' );

// Verify there is no selected block.
Expand Down

0 comments on commit cbd8168

Please sign in to comment.