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-consent: Added a11y focusing for consent UI #20750

Merged
merged 5 commits into from Mar 4, 2019

Conversation

torch2424
Copy link
Contributor

@torch2424 torch2424 commented Feb 9, 2019

relates to #17257

This adds some a11y support to UIs in amp-consent. This automatically focuses on UIs that are shown, and are not post prompt. On hide, the focus is then returned that the element was focus on before. This follows the method mentioned at this a11y blog post.

Also, this updates the examples to add some missing scripts, and support the focus on the CMP iframe

NOTE: I used the /*OK*/ for the .focus() calls. As focus was a part of the Paul Irish Layout Reflow gist, but in our case we do this on a user action or mutateElement, so I assume this would be okay?

Example

Please see the orange outline for where my chromevox shows focus. I know it may look a little weird, but from my experience using chrome vox, everything seems to flow well and can be accessed. 😄

ampconsenta11y

Copy link
Contributor

@zhouyx zhouyx left a comment

Choose a reason for hiding this comment

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

Sorry for the late review. One comment as we talked offline.

@@ -244,6 +262,11 @@ export class ConsentUI {
this.baseInstance_.getViewport().removeFromFixedLayer(this.parent_);
toggle(dev().assertElement(this.ui_), false);
this.isVisible_ = false;

if (this.elementWithFocusBeforeShowing_) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As we agreed, if this.elementWithFocusBeforeShowing_ == null, can we focus on the first element of the page.

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. Used children[0] instead of firstChild due to: https://stackoverflow.com/questions/10474676/get-immediate-first-child-element

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you. Do you know what happens if children[0] is not focusable? Ideally we want to find and cache the first focusable element. Don't want to block you, we can leave that as a TODO

@torch2424 torch2424 merged commit 53ae578 into ampproject:master Mar 4, 2019
@torch2424 torch2424 deleted the amp-consent-a11y branch March 4, 2019 22:38
noranazmy pushed a commit to noranazmy/amphtml that referenced this pull request Mar 22, 2019
* Added a11y focusing for consent UI

* Made PR Fix

* Made PR Comments

* Fixed linting
bramanudom pushed a commit to bramanudom/amphtml that referenced this pull request Mar 22, 2019
* Added a11y focusing for consent UI

* Made PR Fix

* Made PR Comments

* Fixed linting
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.

None yet

3 participants