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

Fix: Embed Block: Match HTML in the editor and frontend #65478

Merged
merged 8 commits into from
Oct 8, 2024
21 changes: 19 additions & 2 deletions packages/block-library/src/embed/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { useBlockProps } from '@wordpress/block-editor';
import { store as coreStore } from '@wordpress/core-data';
import { View } from '@wordpress/primitives';
import { getAuthority } from '@wordpress/url';
import { Caption } from '../utils/caption';

const EmbedEdit = ( props ) => {
const {
Expand Down Expand Up @@ -261,7 +262,15 @@ const EmbedEdit = ( props ) => {
toggleResponsive={ toggleResponsive }
switchBackToURLInput={ () => setIsEditingURL( true ) }
/>
<View { ...blockProps }>
<figure
{ ...blockProps }
className={ clsx( blockProps.className, className, {
[ `is-type-${ type }` ]: type,
[ `is-provider-${ providerNameSlug }` ]: providerNameSlug,
[ `wp-block-embed-${ providerNameSlug }` ]:
providerNameSlug,
} ) }
>
<EmbedPreview
preview={ preview }
previewable={ previewable }
Expand All @@ -279,7 +288,15 @@ const EmbedEdit = ( props ) => {
attributes={ attributes }
setAttributes={ setAttributes }
/>
</View>
<Caption
attributes={ attributes }
setAttributes={ setAttributes }
isSelected={ isSelected }
insertBlocksAfter={ insertBlocksAfter }
label={ __( 'Embed caption text' ) }
showToolbarButton={ isSelected }
/>
</figure>
</>
);
};
Expand Down
20 changes: 2 additions & 18 deletions packages/block-library/src/embed/embed-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { getAuthority } from '@wordpress/url';
* Internal dependencies
*/
import WpEmbedPreview from './wp-embed-preview';
import { Caption } from '../utils/caption';

export default function EmbedPreview( {
preview,
Expand All @@ -32,9 +31,6 @@ export default function EmbedPreview( {
className,
icon,
label,
insertBlocksAfter,
attributes,
setAttributes,
} ) {
const [ interactive, setInteractive ] = useState( false );

Expand Down Expand Up @@ -96,11 +92,7 @@ export default function EmbedPreview( {
/* eslint-enable jsx-a11y/no-static-element-interactions */

return (
<figure
className={ clsx( className, 'wp-block-embed', {
'is-type-video': 'video' === type,
} ) }
>
<>
{ previewable ? (
embedWrapper
) : (
Expand All @@ -122,14 +114,6 @@ export default function EmbedPreview( {
</p>
</Placeholder>
) }
<Caption
attributes={ attributes }
setAttributes={ setAttributes }
isSelected={ isSelected }
insertBlocksAfter={ insertBlocksAfter }
label={ __( 'Embed caption text' ) }
showToolbarButton={ isSelected }
/>
</figure>
</>
);
}
6 changes: 3 additions & 3 deletions test/e2e/specs/editor/various/embedding.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ test.describe( 'Embedding content', () => {
'https://developer.wordpress.org/block-editor/reference-guides/block-api/block-attributes/'
);
await expect(
currenEmbedBlock.locator( 'figure' ),
currenEmbedBlock,
'WordPress valid content. Should render valid figure element.'
).toHaveClass( 'wp-block-embed' );
).toHaveClass( /wp-block-embed/ );

await embedUtils.insertEmbed(
'https://www.youtube.com/watch?v=lXMskKTw3Bc'
);
await expect(
currenEmbedBlock.locator( 'figure' ),
currenEmbedBlock,
'Video content. Should render valid figure element, and include the aspect ratio class.'
).toHaveClass( /wp-embed-aspect-16-9/ );

Expand Down
Loading