-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Conversation
There was a problem hiding this 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_) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
* Added a11y focusing for consent UI * Made PR Fix * Made PR Comments * Fixed linting
* Added a11y focusing for consent UI * Made PR Fix * Made PR Comments * Fixed linting
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 ormutateElement
, 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. 😄