Skip to content

Commit ca62492

Browse files
authored
Add text control for background media alt text (#3214)
1 parent e0d26ca commit ca62492

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

assets/src/stories-editor/blocks/amp-story-page/edit.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ div[data-type="amp/amp-story-page"] .wp-block-image {
227227
margin-top: 0;
228228
}
229229

230+
.edit-post-settings-sidebar__panel-block .components-focal-point-picker_position-display-container > .components-base-control {
231+
margin-bottom: 0;
232+
}
233+
230234
/* Block Validation Warnings */
231235

232236
.editor-block-list__layout [data-type="amp/amp-story-page"] .block-editor-block-list__block .block-editor-warning {

assets/src/stories-editor/blocks/amp-story-page/edit.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
Notice,
2626
SelectControl,
2727
RangeControl,
28+
TextControl,
2829
ResponsiveWrapper,
2930
} from '@wordpress/components';
3031
import {
@@ -214,6 +215,7 @@ class PageEdit extends Component {
214215
mediaId,
215216
mediaType,
216217
mediaUrl,
218+
mediaAlt,
217219
focalPoint = { x: 0.5, y: 0.5 },
218220
overlayOpacity,
219221
poster,
@@ -404,6 +406,14 @@ class PageEdit extends Component {
404406
onChange={ ( value ) => setAttributes( { focalPoint: value } ) }
405407
/>
406408
) }
409+
{ mediaType && (
410+
<TextControl
411+
label={ __( 'Assistive Text', 'amp' ) }
412+
help={ __( 'This text is used to inform visually impaired users about the background content.', 'amp' ) }
413+
value={ mediaAlt }
414+
onChange={ ( label ) => setAttributes( { mediaAlt: label } ) }
415+
/>
416+
) }
407417
</>
408418
</PanelBody>
409419
<PanelBody title={ __( 'Page Settings', 'amp' ) }>
@@ -464,6 +474,7 @@ PageEdit.propTypes = {
464474
poster: PropTypes.string,
465475
autoAdvanceAfter: PropTypes.string,
466476
autoAdvanceAfterDuration: PropTypes.number,
477+
mediaAlt: PropTypes.string,
467478
} ).isRequired,
468479
setAttributes: PropTypes.func.isRequired,
469480
media: PropTypes.object,

tests/e2e/specs/stories-editor/page.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import {
1616
insertBlock,
1717
} from '../../utils';
1818

19+
const LARGE_IMAGE = 'large-image-36521.jpg';
20+
const CORRECT_VIDEO = 'clothes-hanged-to-dry-1295231.mp4';
21+
const SELECT_BUTTON = '.media-modal button.media-button-select';
22+
1923
describe( 'Story Page', () => {
2024
beforeAll( async () => {
2125
await activateExperience( 'stories' );
@@ -167,4 +171,51 @@ describe( 'Story Page', () => {
167171
return document.querySelector( selector ).value;
168172
}, secondsSelector ) ).toBe( '2' );
169173
} );
174+
175+
it( 'should allow changing the alt attribute for the background image', async () => {
176+
// Add background image.
177+
await page.waitForSelector( '.editor-amp-story-page-background' );
178+
await page.click( '.editor-amp-story-page-background' );
179+
await uploadMedia( LARGE_IMAGE );
180+
await expect( page ).toClick( SELECT_BUTTON );
181+
182+
// Write assistive text.
183+
const label = await page.waitForXPath( `//label[contains(text(), 'Assistive Text')]` );
184+
await page.evaluate( ( lbl ) => {
185+
lbl.click();
186+
}, label );
187+
await page.keyboard.type( 'Hello World' );
188+
189+
// Open preview.
190+
const editorPage = page;
191+
const previewPage = await openPreviewPage( editorPage, 'amp-story' );
192+
await previewPage.waitForSelector( 'amp-img[alt*="Hello World"]' );
193+
} );
194+
195+
/**
196+
* This test is disabled because it does not work on Chromium.
197+
*
198+
* @see https://github.com/ampproject/amp-wp/pull/2874
199+
* @see https://github.com/ampproject/amp-wp/pull/3214
200+
*/
201+
// eslint-disable-next-line jest/no-disabled-tests
202+
it.skip( 'should allow changing the ARIA label for the background video', async () => {
203+
// Add background video.
204+
await page.waitForSelector( '.editor-amp-story-page-background' );
205+
await page.click( '.editor-amp-story-page-background' );
206+
await uploadMedia( CORRECT_VIDEO );
207+
await expect( page ).toClick( SELECT_BUTTON );
208+
209+
// Write assistive text.
210+
const label = await page.waitForXPath( `//label[contains(text(), 'Assistive Text')]` );
211+
await page.evaluate( ( lbl ) => {
212+
lbl.click();
213+
}, label );
214+
await page.keyboard.type( 'Hello World' );
215+
216+
// Open preview.
217+
const editorPage = page;
218+
const previewPage = await openPreviewPage( editorPage, 'amp-story' );
219+
await previewPage.waitForXPath( '//amp-video[contains(@aria-label, "Hello World")]' );
220+
} );
170221
} );

0 commit comments

Comments
 (0)