Skip to content

Commit

Permalink
Add alert role to user-notification by default (#5896)
Browse files Browse the repository at this point in the history
* add role=alert by default

* grammar

* fix lint
  • Loading branch information
William Chou authored Oct 28, 2016
1 parent 32ddf63 commit d257e82
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions extensions/amp-user-notification/0.1/amp-user-notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ export class AmpUserNotification extends AMP.BaseElement {
assertHttpsUrl(this.dismissHref_, this.element);
}

// Default to alert role if unspecified.
const roleAttribute = this.element.getAttribute('role');
if (!roleAttribute) {
this.element.setAttribute('role', 'alert');
}

const persistDismissal = this.element.getAttribute(
'data-persist-dismissal');
/** @private @const {boolean} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,22 @@ describe('amp-user-notification', () => {
});
});

it('should have a default `role` if unspecified', () => {
return getUserNotification({id: 'n1'}).then(el => {
const impl = el.implementation_;
impl.buildCallback();
expect(el.getAttribute('role')).to.equal('alert');
});
});

it('should not override `role` if specified', () => {
return getUserNotification({id: 'n1', role: 'status'}).then(el => {
const impl = el.implementation_;
impl.buildCallback();
expect(el.getAttribute('role')).to.equal('status');
});
});

describe('buildGetHref_', () => {

it('should do url replacement', () => {
Expand Down

0 comments on commit d257e82

Please sign in to comment.