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

♿ [Story a11y] Improve tabbing on social-share and bookend #32859

Merged

Conversation

mszylkowski
Copy link
Contributor

@mszylkowski mszylkowski commented Feb 24, 2021

Part of #31747
Mentioned in #32511

When tabbing through the story, landing on the share icons or the bookend links will scroll the viewport outside the story area.

Changes:

  • When showing or hiding the share menu, toggle the share icons to tabbable.
  • Toggle the links on the bookend to tabbable when bookend is open
  • Bring back focus state:
    image

@ampproject/wg-stories

@mszylkowski mszylkowski self-assigned this Feb 24, 2021
@mszylkowski mszylkowski added this to In progress in wg-stories Sprint via automation Feb 24, 2021
@mszylkowski mszylkowski marked this pull request as ready for review February 24, 2021 19:34
@amp-owners-bot
Copy link

amp-owners-bot bot commented Feb 24, 2021

Hey @gmajoulet, @newmuis, @Enriqe! These files were changed:

extensions/amp-story/1.0/amp-story-bookend.css
extensions/amp-story/1.0/amp-story-draggable-drawer.css
extensions/amp-story/1.0/amp-story-draggable-drawer.js
extensions/amp-story/1.0/amp-story-page-attachment.css
extensions/amp-story/1.0/amp-story-share-menu.css
extensions/amp-story/1.0/amp-story-share.css
extensions/amp-story/1.0/amp-story-share.js
extensions/amp-story/1.0/amp-story-vertical.css

@processprocess
Copy link
Contributor

processprocess commented Feb 24, 2021

An alternate approach:
putting visibility: hidden on the parent when it's not open might prevent the elements from being tabbable.

It may have side effects depending on which node is being transformed.
I'm also not sure how it works with shadow dom. It might need to be on a parent that's in the same shadow dom.

Do you think there's value in trying that? It might be less code.

@mszylkowski
Copy link
Contributor Author

@processprocess Absolutely, let me try that. I suspect that the animations would break since we're hiding the element when not visible

@mszylkowski
Copy link
Contributor Author

mszylkowski commented Feb 24, 2021

@processprocess seems like the shadow dom does interfere but it was worth the effort to get it working through the shadow dom since the code is much clearer this way, PTAL. Animations don't break since the visibility attribute changes gradually

@processprocess
Copy link
Contributor

processprocess commented Feb 25, 2021

This looks great to me. Thanks Matias :)

I noticed "Get link" gets skipped when tabbing. It looks like screen readers don't recognize it. I think that needs to be fixed.
It's somewhat related to this PR. Do you think it makes sense to do that work in this PR or split it into a new one?

Screen Shot 2021-02-25 at 10 32 12 AM

Copy link
Contributor

@gmajoulet gmajoulet left a comment

Choose a reason for hiding this comment

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

We already set aria-hidden=bool from the draggable-drawer class, that's supposed to take care of this

this.element.setAttribute('aria-hidden', false);

Why is this not working? Let's fix it instead of introducing yet another way to do the same thing

@mszylkowski
Copy link
Contributor Author

I noticed "Get link" gets skipped when tabbing. It looks like screen readers don't recognize it. I think that needs to be fixed.
It's somewhat related to this PR. Do you think it makes sense to do that work in this PR or split it into a new one?

@processprocess I'll check if the "copy to clipboard" can be triggered from the keyboard, and if it's a couple of lines of code we can do it here.

We already set aria-hidden=bool from the draggable-drawer class, that's supposed to take care of this

@gmajoulet https://web.dev/aria-hidden-focus/ "Using the aria-hidden="true" attribute on an element hides the element and all its children from screen readers and other assistive technologies. If the hidden element contains a focusable element, assistive technologies won't read the focusable element, but keyboard users will still be able to navigate to it, which can cause confusion."

We may be able to remove the aria-hidden from this if we have visibility: hidden, but for tabbing through the story, the aria-hidden doesn't disable the focusable elements (it does remove them from the a11y tree, but that's different)

@gmajoulet
Copy link
Contributor

gmajoulet commented Feb 25, 2021

That's good to know thank you. So let's write the fix at the same level so the logic is not split in between two files.

The draggable drawer sets aria-hidden to true/false on open/close, and it also sets a i-amphtml-story-draggable-drawer-open class that you can rely on to set the visibility.
I suspect that setting the visibility on the Shadow host might not work and you could still tab through the content within the Shadow root. I won't get into specifics of shadow dom style scoping, but I think adding :host {visibility: inherit !important;} in both amp-story-bookend.css and amp-story-page-attachment.css will make it work.

TLDR: add the visibility rule on i-amphtml-story-draggable-drawer-open, and make sure the :host inherits it in each CSS file.

@mszylkowski
Copy link
Contributor Author

mszylkowski commented Feb 25, 2021

@gmajoulet had to deal with transitioning the visibility with a delay so it doesn't break the animations, but worked. Thanks for the suggestion! PTAL at the fix.

Copy link
Contributor

@processprocess processprocess left a comment

Choose a reason for hiding this comment

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

Approving with a couple nits/suggestions.


.i-amphtml-story-share-icon:active::before {
background-color: #787878 !important;
outline: 2px solid #0389ff !important;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:
It's best practice to not override default browser state for a11y. I think we can remove this override.
The outline below it is a nice touch though to help it be visible.

It might be worth putting a comment above this block stating that it's for a11y.

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 default for these elements (being custom elements / divs and not necessarily buttons) is to not have anything for the focus state, so this is super useful to know what the user is focusing on. I can add a comment, but I wonder if it's not clear enough if it's inside a rule with the :focus selector

@@ -277,6 +289,13 @@ export class ShareWidget {
e.preventDefault();
this.copyUrlToClipboard_();
});
listen(linkShareButton, 'keyup', (e) => {
const code = e.charCode || e.keyCode;
if (code === 32 || code === 13) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:
I wonder if this needs a comment for what keys these are for quick readability.
I think we commonly do top level CONSTs but maybe that's overkill for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to add a comment for this, it's not immediately obvious what these are

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants