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

[ampproject/amphtml] ♿ [Story a11y] Accessible close button in share menu and Twitter overlay #32863

Merged
merged 6 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions extensions/amp-story/1.0/amp-story-share-menu.css
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@
font-size: 24px !important;
line-height: 30px !important;
text-align: center !important;
border: 0 !important;
padding: 0 !important;
background: none !important;
}

[desktop].i-amphtml-story-share-menu .i-amphtml-story-share-item {
Expand Down
25 changes: 21 additions & 4 deletions extensions/amp-story/1.0/amp-story-share-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ import {
} from './amp-story-store-service';
import {CSS} from '../../../build/amp-story-share-menu-1.0.css';
import {Keys} from '../../../src/utils/key-codes';
import {LocalizedStringId} from '../../../src/localized-strings';
import {Services} from '../../../src/services';
import {ShareWidget} from './amp-story-share';
import {closest} from '../../../src/dom';
import {createShadowRootWithStyle} from './utils';
import {dev} from '../../../src/log';
import {dev, devAssert} from '../../../src/log';
import {getAmpdoc} from '../../../src/service';
import {getLocalizationService} from './amp-story-localization-service';
import {htmlFor} from '../../../src/static-template';
import {setStyles} from '../../../src/style';

Expand All @@ -48,9 +50,9 @@ const getTemplate = (element) => {
return htmlFor(element)`
<div class="i-amphtml-story-share-menu i-amphtml-story-system-reset" aria-hidden="true" role="alert">
<div class="i-amphtml-story-share-menu-container">
<span class="i-amphtml-story-share-menu-close-button" role="button">
<button class="i-amphtml-story-share-menu-close-button" aria-label="">
processprocess marked this conversation as resolved.
Show resolved Hide resolved
&times;
</span>
</button>
</div>
</div>`;
};
Expand Down Expand Up @@ -79,6 +81,9 @@ export class ShareMenu {
/** @private {?Element} */
this.element_ = null;

/** @private {?Element} */
this.closeButton_ = null;

/** @private {?Element} */
this.innerContainerEl_ = null;

Expand Down Expand Up @@ -165,6 +170,18 @@ export class ShareMenu {
this.element_ = getTemplate(this.parentEl_);
createShadowRootWithStyle(root, this.element_, CSS);

this.closeButton_ = dev().assertElement(
this.element_.querySelector('.i-amphtml-story-share-menu-close-button')
);
const localizationService = getLocalizationService(
devAssert(this.parentEl_)
);
devAssert(localizationService, 'Could not retrieve LocalizationService.');
const localizedCloseString = localizationService.getLocalizedString(
LocalizedStringId.AMP_STORY_CLOSE_BUTTON_LABEL
);
this.closeButton_.setAttribute('aria-label', localizedCloseString);
processprocess marked this conversation as resolved.
Show resolved Hide resolved

this.initializeListeners_();

this.vsync_.run({
Expand Down Expand Up @@ -252,7 +269,7 @@ export class ShareMenu {
onShareMenuClick_(event) {
const el = dev().assertElement(event.target);

if (el.classList.contains('i-amphtml-story-share-menu-close-button')) {
if (el === this.closeButton_) {
this.close_();
}

Expand Down