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

Add default aria-live attributes to amp-live-list and amp-fresh #8988

Merged
merged 3 commits into from
Apr 28, 2017
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
5 changes: 4 additions & 1 deletion extensions/amp-fresh/0.1/amp-fresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ export class AmpFresh extends AMP.BaseElement {

installAmpFreshManagerForDoc(this.element);
this.manager_ = ampFreshManagerForDoc(this.element);

this.manager_.register(this.ampFreshId_, this);

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

/**
Expand Down
11 changes: 11 additions & 0 deletions extensions/amp-fresh/0.1/test/test-amp-fresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,15 @@ describe('amp-fresh', () => {
expect(fresh.element.innerHTML).to.equal(
'<span>hello</span><div>world</div>!');
});

it('should have aria-live=polite by default', () => {
fresh.buildCallback();
expect(fresh.element.getAttribute('aria-live')).to.equal('polite');
});

it('should use explicitly defined aria-live attribute value', () => {
elem.setAttribute('aria-live', 'assertive');
fresh.buildCallback();
expect(fresh.element.getAttribute('aria-live')).to.equal('assertive');
});
});
4 changes: 4 additions & 0 deletions extensions/amp-live-list/0.1/amp-live-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ export class AmpLiveList extends AMP.BaseElement {
this.itemsSlot_, true);

this.registerAction('update', this.updateAction_.bind(this));

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

/** @override */
Expand Down
18 changes: 18 additions & 0 deletions extensions/amp-live-list/0.1/test/test-amp-live-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,24 @@ describe('amp-live-list', () => {
}).to.throw(/must have an "items" slot/);
});

it('should have aria-live=polite by default', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

actual code is testing the override case though (same issue with test-amp-fresh.js as well) Let's have two tests, one for default and one for override.

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

buildElement(elem, dftAttrs);
liveList.buildCallback();
expect(liveList.element.getAttribute('aria-live')).to.equal('polite');
});

it('should use explicitly defined aria-live attribute value', () => {
buildElement(elem, {
'aria-live': 'assertive',
'id': 'my-list',
'data-poll-interval': 2000,
'data-max-items-per-page': 5,
'data-sort-time': Date.now(),
});
liveList.buildCallback();
expect(liveList.element.getAttribute('aria-live')).to.equal('assertive');
});

describe('#update', () => {

beforeEach(() => {
Expand Down