diff --git a/packages/block-library/src/audio/audio-toolbar.js b/packages/block-library/src/audio/audio-toolbar.js
new file mode 100644
index 0000000000000..db58b0d034cf9
--- /dev/null
+++ b/packages/block-library/src/audio/audio-toolbar.js
@@ -0,0 +1,31 @@
+/**
+ * External dependencies
+ */
+import classnames from 'classnames';
+
+/**
+ * WordPress dependencies
+ */
+import {
+ IconButton,
+ Path,
+ Rect,
+ SVG,
+ Toolbar,
+} from '@wordpress/components';
+import { __ } from '@wordpress/i18n';
+
+export default function AudioToolbar( props ) {
+ const { isEditing, onClick } = props;
+
+ const editImageIcon = ( );
+
+ return
+
+ ;
+}
diff --git a/packages/block-library/src/audio/edit.js b/packages/block-library/src/audio/edit.js
index 1545378ddc0c7..bb1e803f0d4b7 100644
--- a/packages/block-library/src/audio/edit.js
+++ b/packages/block-library/src/audio/edit.js
@@ -4,11 +4,9 @@
import { getBlobByURL, isBlobURL } from '@wordpress/blob';
import {
Disabled,
- IconButton,
PanelBody,
SelectControl,
ToggleControl,
- Toolbar,
withNotices,
} from '@wordpress/components';
import {
@@ -26,11 +24,13 @@ import { __ } from '@wordpress/i18n';
* Internal dependencies
*/
import icon from './icon';
+import AudioToolbar from './audio-toolbar';
/**
* Internal dependencies
*/
import { createUpgradedEmbedBlock } from '../embed/util';
+import { speak } from '@wordpress/a11y';
const ALLOWED_MEDIA_TYPES = [ 'audio' ];
@@ -40,7 +40,7 @@ class AudioEdit extends Component {
// edit component has its own src in the state so it can be edited
// without setting the actual value outside of the edit UI
this.state = {
- editing: ! this.props.attributes.src,
+ isEditing: ! this.props.attributes.src,
};
this.toggleAttribute = this.toggleAttribute.bind( this );
@@ -62,7 +62,7 @@ class AudioEdit extends Component {
},
onError: ( e ) => {
setAttributes( { src: undefined, id: undefined } );
- this.setState( { editing: true } );
+ this.setState( { isEditing: true } );
noticeOperations.createErrorNotice( e );
},
allowedTypes: ALLOWED_MEDIA_TYPES,
@@ -81,8 +81,8 @@ class AudioEdit extends Component {
const { attributes, setAttributes } = this.props;
const { src } = attributes;
- // Set the block's src from the edit component's state, and switch off
- // the editing UI.
+ // Set the block's src from the edit component's state, and toggle off
+ // the isEditing UI.
if ( newSrc !== src ) {
// Check if there's an embed block that handles this URL.
const embedBlock = createUpgradedEmbedBlock(
@@ -95,7 +95,7 @@ class AudioEdit extends Component {
setAttributes( { src: newSrc, id: undefined } );
}
- this.setState( { editing: false } );
+ this.setState( { isEditing: false } );
}
getAutoplayHelp( checked ) {
@@ -105,28 +105,41 @@ class AudioEdit extends Component {
render() {
const { autoplay, caption, loop, preload, src } = this.props.attributes;
const { setAttributes, isSelected, className, noticeOperations, noticeUI } = this.props;
- const { editing } = this.state;
- const switchToEditing = () => {
- this.setState( { editing: true } );
+ const { isEditing } = this.state;
+ const toggleIsEditing = () => {
+ this.setState( { isEditing: ! this.state.isEditing } );
+ if ( this.state.isEditing ) {
+ speak( __( 'You can now listen to the audio in the audio block.' ) );
+ } else {
+ speak( __( 'You are now editing the audio in the audio block.' ) );
+ }
};
const onSelectAudio = ( media ) => {
if ( ! media || ! media.url ) {
- // in this case there was an error and we should continue in the editing state
+ // in this case there was an error and we should continue in the isEditing state
// previous attributes should be removed because they may be temporary blob urls
setAttributes( { src: undefined, id: undefined } );
- switchToEditing();
+ toggleIsEditing();
return;
}
// sets the block's attribute and updates the edit component from the
- // selected media, then switches off the editing UI
+ // selected media, then toggles off the isEditing UI
setAttributes( { src: media.url, id: media.id } );
- this.setState( { src: media.url, editing: false } );
+ this.setState( { src: media.url, isEditing: false } );
};
- if ( editing ) {
- return (
-
+
+ { !! src &&
+
+ }
+
+ { isEditing && }
className={ className }
+ onCancel={ !! src && toggleIsEditing }
onSelect={ onSelectAudio }
onSelectURL={ this.onSelectURL }
accept="audio/*"
@@ -134,24 +147,8 @@ class AudioEdit extends Component {
value={ this.props.attributes }
notices={ noticeUI }
onError={ noticeOperations.createErrorNotice }
- />
- );
- }
-
- /* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */
- return (
- <>
-
-
-
-
-
-
+ /> }
+ { ! isEditing &&
-
- }
+ { ! isEditing &&
+ }
>
);
/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role, jsx-a11y/click-events-have-key-events */