Skip to content

Commit a19c2ea

Browse files
Mamadukayogeshbhutkarfabiankaegy
authored andcommitted
Video: Fix 'MediaUploadCheck' wrapper for Poster control (WordPress#70830)
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: yogeshbhutkar <yogeshbhutkar@git.wordpress.org> Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>
1 parent 32830b3 commit a19c2ea

3 files changed

Lines changed: 30 additions & 34 deletions

File tree

packages/block-library/src/video/edit.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
} from '@wordpress/block-editor';
2424
import { useRef, useEffect, useState } from '@wordpress/element';
2525
import { __ } from '@wordpress/i18n';
26-
import { useInstanceId } from '@wordpress/compose';
2726
import { useDispatch } from '@wordpress/data';
2827
import { video as icon } from '@wordpress/icons';
2928
import { store as noticesStore } from '@wordpress/notices';
@@ -52,7 +51,6 @@ function VideoEdit( {
5251
insertBlocksAfter,
5352
onReplace,
5453
} ) {
55-
const instanceId = useInstanceId( VideoEdit );
5654
const videoPlayer = useRef();
5755
const { id, controls, poster, src, tracks } = attributes;
5856
const [ temporaryURL, setTemporaryURL ] = useState( attributes.blob );
@@ -210,7 +208,7 @@ function VideoEdit( {
210208
muted: false,
211209
playsInline: false,
212210
preload: 'metadata',
213-
poster: '',
211+
poster: undefined,
214212
} );
215213
} }
216214
dropdownMenuProps={ dropdownMenuProps }
@@ -222,7 +220,6 @@ function VideoEdit( {
222220
<PosterImage
223221
poster={ poster }
224222
setAttributes={ setAttributes }
225-
instanceId={ instanceId }
226223
/>
227224
</ToolsPanel>
228225
</InspectorControls>

packages/block-library/src/video/editor.scss

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@
1919
}
2020
}
2121

22-
.editor-video-poster-control {
23-
.components-button {
24-
margin-right: $grid-unit-10;
25-
}
26-
}
27-
2822
.block-library-video-tracks-editor {
2923
z-index: z-index("{core/video track editor popover}");
3024
}

packages/block-library/src/video/poster-image.js

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@ import { MediaUpload, MediaUploadCheck } from '@wordpress/block-editor';
55
import {
66
Button,
77
BaseControl,
8+
__experimentalHStack as HStack,
89
__experimentalToolsPanelItem as ToolsPanelItem,
910
} from '@wordpress/components';
1011
import { __, sprintf } from '@wordpress/i18n';
1112
import { useRef } from '@wordpress/element';
13+
import { useInstanceId } from '@wordpress/compose';
1214

13-
function PosterImage( { poster, setAttributes, instanceId } ) {
14-
const posterImageButton = useRef();
15-
const VIDEO_POSTER_ALLOWED_MEDIA_TYPES = [ 'image' ];
15+
const VIDEO_POSTER_ALLOWED_MEDIA_TYPES = [ 'image' ];
1616

17-
const videoPosterDescription = `video-block__poster-image-description-${ instanceId }`;
17+
function PosterImage( { poster, setAttributes } ) {
18+
const posterButtonRef = useRef();
19+
const descriptionId = useInstanceId(
20+
PosterImage,
21+
'video-block__poster-image-description'
22+
);
1823

1924
function onSelectPoster( image ) {
2025
setAttributes( { poster: image.url } );
@@ -24,23 +29,23 @@ function PosterImage( { poster, setAttributes, instanceId } ) {
2429
setAttributes( { poster: undefined } );
2530

2631
// Move focus back to the Media Upload button.
27-
posterImageButton.current.focus();
32+
posterButtonRef.current.focus();
2833
}
2934

3035
return (
31-
<ToolsPanelItem
32-
label={ __( 'Poster image' ) }
33-
isShownByDefault
34-
hasValue={ () => !! poster }
35-
onDeselect={ () => {
36-
setAttributes( { poster: '' } );
37-
} }
38-
>
39-
<MediaUploadCheck>
40-
<div className="editor-video-poster-control">
41-
<BaseControl.VisualLabel>
42-
{ __( 'Poster image' ) }
43-
</BaseControl.VisualLabel>
36+
<MediaUploadCheck>
37+
<ToolsPanelItem
38+
label={ __( 'Poster image' ) }
39+
isShownByDefault
40+
hasValue={ () => !! poster }
41+
onDeselect={ () => {
42+
setAttributes( { poster: undefined } );
43+
} }
44+
>
45+
<BaseControl.VisualLabel>
46+
{ __( 'Poster image' ) }
47+
</BaseControl.VisualLabel>
48+
<HStack justify="flex-start">
4449
<MediaUpload
4550
title={ __( 'Select poster image' ) }
4651
onSelect={ onSelectPoster }
@@ -50,14 +55,14 @@ function PosterImage( { poster, setAttributes, instanceId } ) {
5055
__next40pxDefaultSize
5156
variant="primary"
5257
onClick={ open }
53-
ref={ posterImageButton }
54-
aria-describedby={ videoPosterDescription }
58+
ref={ posterButtonRef }
59+
aria-describedby={ descriptionId }
5560
>
5661
{ ! poster ? __( 'Select' ) : __( 'Replace' ) }
5762
</Button>
5863
) }
5964
/>
60-
<p id={ videoPosterDescription } hidden>
65+
<p id={ descriptionId } hidden>
6166
{ poster
6267
? sprintf(
6368
/* translators: %s: poster image URL. */
@@ -77,9 +82,9 @@ function PosterImage( { poster, setAttributes, instanceId } ) {
7782
{ __( 'Remove' ) }
7883
</Button>
7984
) }
80-
</div>
81-
</MediaUploadCheck>
82-
</ToolsPanelItem>
85+
</HStack>
86+
</ToolsPanelItem>
87+
</MediaUploadCheck>
8388
);
8489
}
8590

0 commit comments

Comments
 (0)