Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♿ [amp-render] a11y change #34540

Merged
merged 10 commits into from
May 27, 2021
12 changes: 4 additions & 8 deletions extensions/amp-render/1.0/amp-render.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ export class AmpRender extends BaseElement {
this.initialSrc_ = this.element.getAttribute('src');
this.src_ = this.initialSrc_;

if (!this.element.hasAttribute('aria-live')) {
this.element.setAttribute('aria-live', 'polite');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another question - does this have to be on the custom element? Can it be done in the Preact layer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this attribute is added to the Preact layer, any changes to placeholder & fallback will not be announced by screen readers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. What about changes within the Preact component, such as actual data rendering into a template? I assume that will be announced by AMP because of this logic but not in Preact? If we add the attribute in Preact layer also, will it cause redundant announcements? If not, perhaps both locations is a good compromise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, with the current logic any changes to the content including placeholder, fallback and rendered data will be announced. By moving it just to the Preact layer, it skips announcing fallback and placeholder updates.

I added the attribute to the Preact layer too and based on testing with VoiceOver on Mac, there are no redundant announcements. Guess that's a good compromise 🙂


this.registerApiAction('refresh', (api) => {
const src = this.element.getAttribute('src');
// There is an alternative way to do this using `mutationObserverCallback` while using a boolean
Expand Down Expand Up @@ -207,14 +211,6 @@ export class AmpRender extends BaseElement {
});
}

/** @override */
buildCallback() {
super.buildCallback();
if (!this.element.hasAttribute('aria-live')) {
this.element.setAttribute('aria-live', 'polite');
}
}

/** @override */
mutationObserverCallback() {
const src = this.element.getAttribute('src');
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-render/1.0/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function RenderWithRef(
rendered && typeof rendered == 'object' && '__html' in rendered;

return (
<Wrapper {...rest} dangerouslySetInnerHTML={isHtml ? rendered : null}>
<Wrapper {...rest} dangerouslySetInnerHTML={isHtml ? rendered : null} aria-live="polite">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please propagate if an aria-live value is passed through props and add unit tests for this layer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{isHtml ? null : rendered}
</Wrapper>
);
Expand Down
4 changes: 4 additions & 0 deletions extensions/amp-render/1.0/component.type.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ var RenderDef = {};
* src: (!string),
* getJson: (!Function),
* render: (?RendererFunctionType|undefined),
* onLoading: (Function),
* onReady: (Function),
* onRefresh: (Function),
* onError: (Function),
* }}
*/
RenderDef.Props;
Expand Down
6 changes: 2 additions & 4 deletions extensions/amp-render/1.0/test/test-amp-render.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,6 @@ describes.realWin(
`;
doc.body.appendChild(element);

await element.buildInternal();
await waitFor(() => {
const div = element.querySelector(`[placeholder]`);
return div && div.textContent;
Expand All @@ -547,9 +546,9 @@ describes.realWin(

expect(placeholder.textContent).to.equal('Loading data');

await element.buildInternal();
fetchStub.resolves({name: 'Joe'});
const text = await getRenderedData();
expect(text).to.equal('Hello Joe');
await waitForText(element, 'Hello Joe');
expect(fetchStub).to.be.calledOnce;
});

Expand All @@ -574,7 +573,6 @@ describes.realWin(
doc.body.appendChild(element);

await whenUpgradedToCustomElement(element);
await element.buildInternal();

fetchStub.rejects();
await element.buildInternal();
Expand Down