Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Embed a simple audio player. ([Source](https://github.com/WordPress/gutenberg/tr
- **Name:** core/audio
- **Category:** media
- **Supports:** align, anchor, interactivity (clientNavigation), spacing (margin, padding)
- **Attributes:** autoplay, blob, caption, id, loop, preload, src
- **Attributes:** autoplay, blob, caption, id, loop, preload, src, transcript

## Avatar

Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/src/audio/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
"source": "attribute",
"selector": "audio",
"attribute": "preload"
},
"transcript": {
"type": "string",
"default": ""
}
},
"supports": {
Expand Down
17 changes: 16 additions & 1 deletion packages/block-library/src/audio/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
InspectorControls,
MediaPlaceholder,
MediaReplaceFlow,
RichText,
useBlockProps,
useBlockEditingMode,
} from '@wordpress/block-editor';
Expand Down Expand Up @@ -50,7 +51,7 @@ function AudioEdit( {
isSelected: isSingleSelected,
insertBlocksAfter,
} ) {
const { id, autoplay, loop, preload, src } = attributes;
const { id, autoplay, loop, preload, src, transcript } = attributes;
const [ temporaryURL, setTemporaryURL ] = useState( attributes.blob );
const blockEditingMode = useBlockEditingMode();
const hasNonContentControls = blockEditingMode === 'default';
Expand Down Expand Up @@ -269,6 +270,20 @@ function AudioEdit( {
isSingleSelected && hasNonContentControls
}
/>
{ ( ! RichText.isEmpty( transcript ) || isSingleSelected ) && (
<RichText
tagName="p"
className="wp-block-audio__transcript-text"
value={ transcript }
onChange={ ( value ) =>
setAttributes( { transcript: value } )
}
placeholder={ __(
'Add a transcript to make your audio accessible to a wider range of users.'
) }
identifier="transcript"
/>
) }
</figure>
</>
);
Expand Down
35 changes: 21 additions & 14 deletions packages/block-library/src/audio/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,35 @@ import {
} from '@wordpress/block-editor';

export default function save( { attributes } ) {
const { autoplay, caption, loop, preload, src } = attributes;
const { autoplay, caption, loop, preload, src, transcript } = attributes;

const displayCaption = ! RichText.isEmpty( caption );

return (
src && (
<figure { ...useBlockProps.save() }>
<figure { ...useBlockProps.save() }>
{ src && (
<audio
controls="controls"
src={ src }
autoPlay={ autoplay }
loop={ loop }
preload={ preload }
/>
{ ! RichText.isEmpty( caption ) && (
<RichText.Content
tagName="figcaption"
value={ caption }
className={ __experimentalGetElementClassName(
'caption'
) }
/>
) }
</figure>
)
) }
{ displayCaption && (
<RichText.Content
tagName="figcaption"
value={ caption }
className={ __experimentalGetElementClassName( 'caption' ) }
/>
) }
{ ! RichText.isEmpty( transcript ) && (
<RichText.Content
tagName="p"
className="wp-block-audio__transcript-text"
value={ transcript }
/>
) }
</figure>
);
}
7 changes: 7 additions & 0 deletions packages/block-library/src/audio/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@
// We restore this as a min-width instead, for alignments.
min-width: 300px;
}

// Transcript styling. Always visible to satisfy WCAG 1.2.1 (text
// alternative for prerecorded audio-only content).
.wp-block-audio__transcript-text {
@include caption-style();
margin-top: 0.5em;
}
}
Loading