Skip to content

Commit

Permalink
Set correct media type for video poster image and manage focus. (#10864)
Browse files Browse the repository at this point in the history
  • Loading branch information
afercia authored Oct 21, 2018
1 parent b3edc71 commit a8fe865
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/block-library/src/video/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
import { getBlobByURL, isBlobURL } from '@wordpress/blob';

const ALLOWED_MEDIA_TYPES = [ 'video' ];
const VIDEO_POSTER_ALLOWED_MEDIA_TYPES = [ 'image' ];

class VideoEdit extends Component {
constructor() {
Expand All @@ -36,6 +37,7 @@ class VideoEdit extends Component {
};

this.videoPlayer = createRef();
this.posterImageButton = createRef();
this.toggleAttribute = this.toggleAttribute.bind( this );
this.onSelectURL = this.onSelectURL.bind( this );
this.onSelectPoster = this.onSelectPoster.bind( this );
Expand Down Expand Up @@ -96,6 +98,9 @@ class VideoEdit extends Component {
onRemovePoster() {
const { setAttributes } = this.props;
setAttributes( { poster: '' } );

// Move focus back to the Media Upload button.
this.posterImageButton.current.focus();
}

render() {
Expand Down Expand Up @@ -200,9 +205,13 @@ class VideoEdit extends Component {
<MediaUpload
title={ __( 'Select Poster Image' ) }
onSelect={ this.onSelectPoster }
allowedTypes={ ALLOWED_MEDIA_TYPES }
allowedTypes={ VIDEO_POSTER_ALLOWED_MEDIA_TYPES }
render={ ( { open } ) => (
<Button isDefault onClick={ open }>
<Button
isDefault
onClick={ open }
ref={ this.posterImageButton }
>
{ ! this.props.attributes.poster ? __( 'Select Poster Image' ) : __( 'Replace image' ) }
</Button>
) }
Expand Down

0 comments on commit a8fe865

Please sign in to comment.