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

amp-sidebar: optional attribute to change text for screen-reader clos… #9958

Merged
merged 33 commits into from Jun 24, 2017

Conversation

rhapsodyai
Copy link
Member

@rhapsodyai rhapsodyai commented Jun 16, 2017

…e button. #9867

Fixed amp-sidebar: optional attribute to change text for screen-reader close button. #9867

Fixes #9867.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If your company signed a CLA, they designated a Point of Contact who decides which employees are authorized to participate. You may need to contact the Point of Contact for your company and ask to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again.

@aghassemi aghassemi self-requested a review June 16, 2017 15:22
package.json Outdated
@@ -51,7 +51,7 @@
"formidable": "1.0.17",
"fs-extra": "0.27.0",
"glob": "7.1.2",
"gulp": "3.9.1",
"gulp": "^3.9.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems we got some extra changes in this commit. Please revert this file.

@@ -98,6 +98,14 @@ export class Platform {
}

/**
* Whether the current browser is based on the WebKit engine.
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems we got some extra changes in this commit. Please revert this file.

yarn.lock Outdated
@@ -48,10 +48,6 @@ acorn-jsx@^3.0.0:
dependencies:
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems we got some extra changes in this commit. Please revert this file.

@@ -122,10 +122,19 @@ export class AmpSidebar extends AMP.BaseElement {
}
});

var ariaLabel = this.element.getAttribute('data-close-button-aria-label')
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be marked as const:

const ariaLabel = ...

@@ -121,10 +121,17 @@ export class AmpSidebar extends AMP.BaseElement {
}
});

var ariaLabel = this.element.getAttribute('data-close-button-aria-label')
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be marked as const:

const ariaLabel = ...

expect(impl.close_).to.have.not.been.called;
closeButton.click();
expect(impl.close_).to.be.calledOnce;

if (options.closeText) { ampsetbar.setAttribute('data-close-button-aria-label', options.closeText) };
Copy link
Contributor

Choose a reason for hiding this comment

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

Please put the if statement body on a new line:

if (option.closeText) {
  ampsetbar.setAttribute(...);
}

// Invisible close button at the end of sidebar for screen-readers.
const screenReaderCloseButton = this.document_.createElement('button');
// TODO(aghassemi, #4146) i18n
screenReaderCloseButton.textContent = 'Close the sidebar';
if(ariaLabel) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Space after if

// TODO(aghassemi, #4146) i18n
screenReaderCloseButton.textContent = 'Close the sidebar';
if(ariaLabel) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Space after if

@googlebot
Copy link

CLAs look good, thanks!

Copy link
Member Author

@rhapsodyai rhapsodyai left a comment

Choose a reason for hiding this comment

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

Hi, I got an email telling me to make the following changes, so I did, I'll cut and paste it here.


@jridgewell requested changes on this pull request.

In package.json:

@@ -51,7 +51,7 @@
"formidable": "1.0.17",
"fs-extra": "0.27.0",
"glob": "7.1.2",

  • "gulp": "3.9.1",
  • "gulp": "^3.9.1",
    Seems we got some extra changes in this commit. Please revert this file.

In src/service/platform-impl.js:

@@ -98,6 +98,14 @@ export class Platform {
}

/**

    • Whether the current browser is based on the WebKit engine.
      Seems we got some extra changes in this commit. Please revert this file.

In yarn.lock:

@@ -48,10 +48,6 @@ acorn-jsx@^3.0.0:
dependencies:
Seems we got some extra changes in this commit. Please revert this file.

In extensions/amp-sidebar/1.0/amp-sidebar.js:

@@ -122,10 +122,19 @@ export class AmpSidebar extends AMP.BaseElement {
}
});

  • var ariaLabel = this.element.getAttribute('data-close-button-aria-label')
    This should be marked as const:

const ariaLabel = ...
In extensions/amp-sidebar/0.1/amp-sidebar.js:

@@ -121,10 +121,17 @@ export class AmpSidebar extends AMP.BaseElement {
}
});

  • var ariaLabel = this.element.getAttribute('data-close-button-aria-label')
    This should be marked as const:

const ariaLabel = ...
In extensions/amp-sidebar/0.1/test/test-amp-sidebar.js:

     expect(impl.close_).to.have.not.been.called;
     closeButton.click();
     expect(impl.close_).to.be.calledOnce;
  •    if (options.closeText) { ampsetbar.setAttribute('data-close-button-aria-label', options.closeText) };
    

Please put the if statement body on a new line:

if (option.closeText) {
ampsetbar.setAttribute(...);
}
In extensions/amp-sidebar/0.1/amp-sidebar.js:

 // Invisible close button at the end of sidebar for screen-readers.
 const screenReaderCloseButton = this.document_.createElement('button');
 // TODO(aghassemi, #4146) i18n
  • screenReaderCloseButton.textContent = 'Close the sidebar';
  • if(ariaLabel) {
    Space after if

In extensions/amp-sidebar/1.0/amp-sidebar.js:

 // TODO(aghassemi, #4146) i18n
  • screenReaderCloseButton.textContent = 'Close the sidebar';
  • if(ariaLabel) {
    Space after if

if (options.closeText) {
ampsetbar.setAttribute('data-close-button-aria-label', options.closeText)
};
expect(closeButton.textContent).to.not.equal(!('Close the sidebar'));
Copy link
Contributor

Choose a reason for hiding this comment

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

This test will have to be done in a separate it test.

Copy link
Member Author

@rhapsodyai rhapsodyai Jun 21, 2017

Choose a reason for hiding this comment

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

Would this it test be okay?

     it('should replace text to screen reader \
     button in data-close-button-aria-label', () => {
       return getAmpSidebar().then(obj =>) {
         if (options.closeText) {
           ampsetbar.setAttribute('data-close-button-aria-label', options.closeText)
         }
       });
     });

Copy link
Contributor

Choose a reason for hiding this comment

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

The options.closeText part will have to be moved into getAmpSidebar, but that should be most of it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean pass it to getAmpSidebar?

it('should replace text to screen reader \
button in data-close-button-aria-label', () => {
return getAmpSidebar().then(obj => {
if (options.closeText) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This will need to be moved inside the getAmpSidebar function.

if (options.closeText) {
ampsetbar.setAttribute('data-close-button-aria-label', options.closeText);
};
expect(closeButton.textContent).to.not.equal(!('Close the sidebar'));
Copy link
Contributor

Choose a reason for hiding this comment

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

expect(closeButton.textContent).to.equal(options.closeText);

it('should replace text to screen reader \
button in data-close-button-aria-label', () => {
return getAmpSidebar().then(obj => {
if (options.closeText) {
Copy link
Contributor

Choose a reason for hiding this comment

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

These next 3 lines sill need to be moved inside getAmpSidebar.

// Invisible close button at the end of sidebar for screen-readers.
const screenReaderCloseButton = this.document_.createElement('button');
// TODO(aghassemi, #4146) i18n
screenReaderCloseButton.textContent = 'Close the sidebar';
if (ariaLabel) {
Copy link
Contributor

Choose a reason for hiding this comment

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

please remove the //TODO line above since it is fixed by this PR

@@ -121,10 +121,17 @@ export class AmpSidebar extends AMP.BaseElement {
}
});

const ariaLabel = this.element.getAttribute('data-close-button-aria-label')
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd recommend:

const ariaLabel = this.element.getAttribute('data-close-button-aria-label') || 'Close the sidebar';

for consistency with other places that do this and also now you can remove the if/else below.

@@ -126,6 +126,10 @@ This attribute is present when the sidebar is open.

This element includes [common attributes](https://www.ampproject.org/docs/reference/common_attributes) extended to AMP components.

##### data-close-button-aria-label attribute
Copy link
Contributor

Choose a reason for hiding this comment

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

##### data-close-button-aria-label**

Optional string used as ARIA label for close button.

for consistency with other places that have this attribute (e.g. amp-image-lightbox)

also please move this above the ##### common attributes

@aghassemi
Copy link
Contributor

@rhapsodyai Please also revert the changes to package-lock.json file.

@rhapsodyai
Copy link
Member Author

I am getting

Found forbidden: ".innerText" in extensions/amp-sidebar/1.0/amp-sidebar.js:150:28 Please review viewport service for helper methods or mark with /OK/or/REVIEW/and consult the AMP team.

when I use:

screenReaderCloseButton.innerText = button.textContent = ariaLabel;

How should I replace this usage?

@rhapsodyai
Copy link
Member Author

@jridgewell @aghassemi Please let me know if the changes I made are ok.

@@ -121,10 +121,14 @@ export class AmpSidebar extends AMP.BaseElement {
}
});

// replacement label for invisible close button set value in amp sidebar
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: capitalize first letter for consistency with other comments

return getAmpSidebar().then(obj => {
const sidebarElement = obj.ampSidebar;
const closeButton = sidebarElement.lastElementChild;
if (options.closeText) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this part needs to move to the getAmpSidebar() method. Then this test becomes:

getAmpSidebar({closeText: 'custom close label'}). then(...
...

expect(closeButton.textContent).to.equal( 'custom close label');

@@ -122,10 +122,14 @@ export class AmpSidebar extends AMP.BaseElement {
}
});

// replacement label for invisible close button set value in amp sidebar
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto same comment above

return getAmpSidebar().then(obj => {
const sidebarElement = obj.ampSidebar;
const closeButton = sidebarElement.lastElementChild;
if (options.closeText) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same here.

@@ -122,6 +122,10 @@ Specifies the display layout of the sidebar, which must be `nodisplay`.

This attribute is present when the sidebar is open.

##### data-close-button-aria-label**

This element includes the value of the aria label attribute for the screenReaderCloseButton text.
Copy link
Contributor

Choose a reason for hiding this comment

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

for consistency with other places we document this attribute please change to:

Optional string used as ARIA label for close button.

@aghassemi
Copy link
Contributor

@rhapsodyai This looks pretty good just a few more requests and then we can merge. Thanks!

@rhapsodyai
Copy link
Member Author

@aghassemi Everything should have been updated. Please let me know if there is something else.

@@ -122,6 +122,10 @@ Specifies the display layout of the sidebar, which must be `nodisplay`.

This attribute is present when the sidebar is open.

##### data-close-button-aria-label**

Optional string used as ARIA label for close button.
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be more like
"Optional attribute used to set ARIA label for the close button added for accessibility"

CC @bpaduch - to review the string

@camelburrito
Copy link
Contributor

@rhapsodyai - your PR has lint errors , you will need to fix this to make this pull request become merge-able

Overall the changes look good! Thanks for contributing

@rhapsodyai
Copy link
Member Author

@camelburrito Thank you, it should be mergeable now.

'data-close-button-aria-label'}).then(obj => {
const sidebarElement = obj.ampSidebar;
const closeButton = sidebarElement.lastElementChild;
if (options.closeText) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@rhapsodyai the following lines:

            if (options.closeText) {
               obj.ampSidebar.setAttribute('data-close-button-aria-label',
                   options.closeText);
             };

should be moved to the getAmpSidebar function definition (line 44 of this file). you can put it right after the if (options.open) { ampSidebar.setAttribute('open', ''); } line.

A bit of background: getAmpSidebar actually creates the sidebar component and since tests may want different configurations of the sidebar component, it already takes an option argument.

@aghassemi
Copy link
Contributor

@rhapsodyai everything looks great, merging now. Thanks!

@aghassemi aghassemi dismissed stale reviews from camelburrito and jridgewell June 24, 2017 05:13

comments addressed

@aghassemi aghassemi merged commit db715a0 into ampproject:master Jun 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

amp-sidebar: optional attribute to change text for screen-reader close button.
5 participants