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] Pagination buttons alt text #32861

Merged
merged 6 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 8 additions & 3 deletions extensions/amp-story/1.0/pagination-buttons.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,14 @@ amp-story:not([desktop]) .i-amphtml-story-button-container {
pointer-events: none !important;
}

/* Navigation buttons. These are only displayed on desktop. */
.i-amphtml-story-button-move {
display: none !important;
/* Navigation button element. Visibly hidden on mobile but focusable 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.

Are they click targets that could cover some content? Should we add pointer-events: none? That might create some P0s.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The click targets could cover content but they're within the 48px area reserved for navigating.
Patch PR for adding pointer-events: none #32917

Screen Shot 2021-02-25 at 11 51 19 AM

amp-story:not([desktop]) .i-amphtml-story-button-move,
[dir=rtl] amp-story:not([desktop]) .i-amphtml-story-button-move {
width: 100% !important;
height: 100% !important;
border: none !important;
background: none !important;
padding: 0 !important;
}

[desktop] .i-amphtml-story-button-move {
Expand Down
40 changes: 21 additions & 19 deletions extensions/amp-story/1.0/pagination-buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import {AdvancementMode} from './story-analytics';
import {CommonSignals} from '../../../src/common-signals';
import {EventType, dispatch} from './events';
import {Services} from '../../../src/services';
import {devAssert} from '../../../src/log';
import {dict} from './../../../src/utils/object';
import {renderAsElement} from './simple-template';
import {dev, devAssert} from '../../../src/log';

import {htmlFor} from '../../../src/static-template';

/** @struct @typedef {{className: string, triggers: (string|undefined)}} */
let ButtonState_1_0_Def; // eslint-disable-line google-camelcase/google-camelcase
Expand Down Expand Up @@ -68,17 +68,15 @@ const ForwardButtonStates = {
},
};

/** @private @const {!./simple-template.ElementDef} */
const BUTTON = {
tag: 'div',
attrs: dict({'class': 'i-amphtml-story-button-container', 'role': 'button'}),
children: [
{
tag: 'button',
attrs: dict({'class': 'i-amphtml-story-button-move'}),
},
],
};
/**
* @param {!Element} element
* @return {!Element}
*/
const buildPaginationButton = (element) =>
htmlFor(element)`
<div class="i-amphtml-story-button-container">
<button class="i-amphtml-story-button-move"></button>
</div>`;

/**
* @param {!Element} hoverEl
Expand Down Expand Up @@ -109,12 +107,16 @@ class PaginationButton {
this.state_ = initialState;

/** @public @const {!Element} */
this.element = renderAsElement(doc, BUTTON);
this.element = buildPaginationButton(doc);

/** @private @const {!Element} */
this.buttonElement_ = dev().assertElement(
this.element.querySelector('button')
);

this.element.classList.add(initialState.className);
initialState.label &&
this.element.setAttribute('aria-label', initialState.label);

this.buttonElement_.setAttribute('aria-label', initialState.label);
this.element.addEventListener('click', (e) => this.onClick_(e));

/** @private @const {!./amp-story-store-service.AmpStoryStoreService} */
Expand All @@ -132,8 +134,8 @@ class PaginationButton {
this.element.classList.remove(this.state_.className);
this.element.classList.add(state.className);
state.label
? this.element.setAttribute('aria-label', state.label)
: this.element.removeAttribute('aria-label');
? this.buttonElement_.setAttribute('aria-label', state.label)
: this.buttonElement_.removeAttribute('aria-label');

this.state_ = state;
}
Expand Down