Skip to content

Commit

Permalink
[amp-video] ♿ override aria-label with alt (#32963)
Browse files Browse the repository at this point in the history
* override aria-label with alt

* Override if title and aria-lable does not exist.

* Update comment.

* override aria-label with alt

* fix merge conflict

* Update extensions/amp-video/0.1/amp-video.js

Co-authored-by: Gabriel Majoulet <gmajoulet@google.com>

Co-authored-by: Gabriel Majoulet <gmajoulet@google.com>
  • Loading branch information
processprocess and gmajoulet committed Mar 1, 2021
1 parent c7bd673 commit 6a74422
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions extensions/amp-video/0.1/amp-video.js
Expand Up @@ -62,6 +62,7 @@ const ATTRS_TO_PROPAGATE_ON_BUILD = [
'crossorigin',
'disableremoteplayback',
'controlsList',
'title',
];

/** @private {!Map<string, number>} the bitrate in Kb/s of amp_quality for videos in the ampproject cdn */
Expand Down Expand Up @@ -236,6 +237,7 @@ export class AmpVideo extends AMP.BaseElement {
this.video_.setAttribute('webkit-playsinline', '');
// Disable video preload in prerender mode.
this.video_.setAttribute('preload', 'none');
this.checkA11yAttributeText_();
this.propagateAttributes(
ATTRS_TO_PROPAGATE_ON_BUILD,
this.video_,
Expand Down Expand Up @@ -269,6 +271,19 @@ export class AmpVideo extends AMP.BaseElement {
Services.videoManagerForDoc(element).register(this);
}

/**
* @private
* Overrides aria-label with alt if aria-label or title is not specified.
*/
checkA11yAttributeText_() {
const altText = this.element.getAttribute('alt');
const hasTitle = this.element.hasAttribute('title');
const hasAriaLabel = this.element.hasAttribute('aria-label');
if (altText && !hasTitle && !hasAriaLabel) {
this.element.setAttribute('aria-label', altText);
}
}

/** @override */
detachedCallback() {
this.updateIsPlaying_(false);
Expand Down

0 comments on commit 6a74422

Please sign in to comment.