Skip to content

Commit

Permalink
Fix: Embed blocks: adding captions via toolbar (#64394)
Browse files Browse the repository at this point in the history
* Add the Caption component to be used for consistency on the embed block similar to audio and image

* Change the label for the embed caption text

Co-authored-by: hbhalodia <[email protected]>
Co-authored-by: Rishit30G <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: simison <[email protected]>
  • Loading branch information
5 people authored Aug 13, 2024
1 parent ad37f20 commit 943b72a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 37 deletions.
9 changes: 9 additions & 0 deletions packages/block-library/src/embed/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { embedContentIcon } from './icons';
import EmbedLoading from './embed-loading';
import EmbedPlaceholder from './embed-placeholder';
import EmbedPreview from './embed-preview';
import { Caption } from '../utils/caption';

/**
* External dependencies
Expand Down Expand Up @@ -277,6 +278,14 @@ const EmbedEdit = ( props ) => {
label={ label }
insertBlocksAfter={ insertBlocksAfter }
/>
<Caption
attributes={ attributes }
setAttributes={ setAttributes }
isSelected={ isSelected }
insertBlocksAfter={ insertBlocksAfter }
label={ __( 'Embed caption text' ) }
showToolbarButton={ isSelected }
/>
</View>
</>
);
Expand Down
40 changes: 3 additions & 37 deletions packages/block-library/src/embed/embed-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ import clsx from 'clsx';
*/
import { __, sprintf } from '@wordpress/i18n';
import { Placeholder, SandBox } from '@wordpress/components';
import {
RichText,
BlockIcon,
__experimentalGetElementClassName,
} from '@wordpress/block-editor';
import { BlockIcon } from '@wordpress/block-editor';
import { Component } from '@wordpress/element';
import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
import { getAuthority } from '@wordpress/url';

/**
Expand Down Expand Up @@ -57,19 +52,8 @@ class EmbedPreview extends Component {
}

render() {
const {
preview,
previewable,
url,
type,
caption,
onCaptionChange,
isSelected,
className,
icon,
label,
insertBlocksAfter,
} = this.props;
const { preview, previewable, url, type, className, icon, label } =
this.props;
const { scripts } = preview;
const { interactive } = this.state;

Expand Down Expand Up @@ -139,24 +123,6 @@ class EmbedPreview extends Component {
</p>
</Placeholder>
) }
{ ( ! RichText.isEmpty( caption ) || isSelected ) && (
<RichText
identifier="caption"
tagName="figcaption"
className={ __experimentalGetElementClassName(
'caption'
) }
placeholder={ __( 'Add caption' ) }
value={ caption }
onChange={ onCaptionChange }
inlineToolbar
__unstableOnSplitAtEnd={ () =>
insertBlocksAfter(
createBlock( getDefaultBlockName() )
)
}
/>
) }
</figure>
);
}
Expand Down

0 comments on commit 943b72a

Please sign in to comment.