@@ -5,16 +5,21 @@ import { MediaUpload, MediaUploadCheck } from '@wordpress/block-editor';
55import {
66 Button ,
77 BaseControl ,
8+ __experimentalHStack as HStack ,
89 __experimentalToolsPanelItem as ToolsPanelItem ,
910} from '@wordpress/components' ;
1011import { __ , sprintf } from '@wordpress/i18n' ;
1112import { 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