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

Accessibility enhancement for the whole shop accounts section #47144

Open
wants to merge 15 commits into
base: trunk
Choose a base branch
from

Conversation

naman03malhotra
Copy link
Contributor

@naman03malhotra naman03malhotra commented May 3, 2024

Submission Review Guidelines:

If you the above steps in trunk the voice ready will not read out the errors.

Changes proposed in this Pull Request:

This PR solves the Accessibility issues for the whole shop accounts section and closes several issues reported by the Author.

  • As part of the fix I wrote a script that focus on the message if a notice is present for both error and failures after the full page reload.
  • Since this only affects the accounts section for now, so I am loading the script only on that route.

Closes #43635 , #43659 , #43636 , #46559

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Use the Safari browser for this testing if you are on a Mac or Chrome for Windows.
  2. Visit accounts section of the shop.
  3. Make sure you are logged out.
  4. Enable Voice reader (On Mac, press CMD + F5). There must be other keys for other OS.
  5. Now try to log in without entering the username or password.
  6. The reader should read out the error message completely.
  7. Next -> The voice reader should read out the error or success message in the following scenarios.
  8. Registering a new account without an email ID or the wrong email ID.
  9. Not submitting the email or username on the forgot password page should read out the error.
  10. Changing account details after login in the account section, try submitting the form without any data, voice reader should read out multiple errors.
  11. Changing the account details with correct data should read out the success message.

Changelog entry

  • Automatically create a changelog entry from the details below.

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Comment

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label May 3, 2024
@naman03malhotra naman03malhotra marked this pull request as ready for review May 3, 2024 14:39
@naman03malhotra naman03malhotra requested review from a team and jorgeatorres and removed request for a team May 3, 2024 14:39
Copy link
Contributor

github-actions bot commented May 3, 2024

Hi @chihsuan, @moon0326, @woocommerce/ghidorah

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

@naman03malhotra naman03malhotra self-assigned this May 3, 2024
@naman03malhotra naman03malhotra added focus: accessibility The issue/PR is related to accessibility. team: Proton labels May 3, 2024
Copy link
Member

@jorgeatorres jorgeatorres left a comment

Choose a reason for hiding this comment

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

Hi @naman03malhotra!

Thanks for picking this up. This seems to be working correctly for block themes, but not for other themes (such as Storefront).
The notices look different (and have different markup) in those:

Screenshot 2024-05-08 at 17 55 02

Also, I wonder if there was a different way to solve this that was more "generic" than adding a script specifically for the accounts page. Not that I'm against that, but similar behavior (though not identical) is implemented in the checkout blocks, for example, when after an error the page scrolls to the notice (though IMHO it doesn't obtain the focus). And I can see this being necessary in other places.

It'd be good to ask Ghidorah for some feedback. What to do you think?

@@ -27,7 +27,7 @@

?>

<div class="wc-block-components-notice-banner is-error" role="alert" <?php echo $multiple ? '' : wc_get_notice_data_attr( $notices[0] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
Copy link
Member

Choose a reason for hiding this comment

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

Why are we removing the role="alert" attribute here? Most (or all?) of the block-notices templates have that, so I guess there must be a reason or at least we should revaluate for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why are we removing the role="alert" attribute here? Most (or all?) of the block-notices templates have that, so I guess there must be a reason or at least we should revaluate for consistency.

That's a good point. For some reason, the other day while I was testing, having role="alert" didn't allow the screen reader to read the multi-line messages, but when I tested again on Safari (and Chrome) today, it was working fine, so I believe it depends on the browser as well.

Another important thing is that role="alert" is not supposed to be used in a full page reload scenario.
image
Ref: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/alert_role

That said,

  • since it is a block template, I am assuming that it will be used in scenarios where we update the message inside the error container dynamically.
  • A bunch of e2e tests also depend on this attribute, keeping all the factors in mind, it makes sense to keep this attribute.

@github-actions github-actions bot removed the focus: e2e tests Issues related to e2e tests label May 9, 2024
@naman03malhotra
Copy link
Contributor Author

This seems to be working correctly for block themes, but not for other themes (such as Storefront).

Thanks for the detailed review @jorgeatorres, great catch! I've made the changes so that it works on both types of themes.

Also, I wonder if there was a different way to solve this that was more "generic" than adding a script specifically for the accounts page. Not that I'm against that, but similar behavior (though not identical) is implemented in the checkout blocks, for example, when after an error the page scrolls to the notice

Good point, so I checked how that works. Actually, they are submitting the form for placing an order using an Ajax call and then updating an aria-live region dynamically using JS, while here we are doing a full page reload. So, the most reliable way I found to grab the screen reader's attention after a full page reload was to bring the alert element in focus.

Copy link
Contributor

github-actions bot commented May 9, 2024

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Test this pull request with WordPress Playground.

Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit.

@naman03malhotra naman03malhotra requested review from a team, chihsuan and moon0326 May 9, 2024 15:25
@naman03malhotra
Copy link
Contributor Author

It'd be good to ask Ghidorah for some feedback. What to do you think?

Good idea, I've requested their feedback.

Copy link
Member

@chihsuan chihsuan left a comment

Choose a reason for hiding this comment

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

So, the most reliable way I found to grab the screen reader's attention after a full page reload was to bring the alert element in focus.

Thanks for sharing @naman03malhotra 🙏 , I did some investigation and agree with you that bringing the alert element seems the best way to grab the screen reader's attention.

I tested with VoiceOver on macOS Safari, and it works as expected with block themes. However, it doesn't work very well with classic themes such as "StoreFront". I tried a few times and sometimes it reads the alert message, but sometimes it doesn't. (It did focus the alert element.)

Screen.Recording.2024-05-14.at.15.15.18.mov

Additionally, I tested it on Chrome. I noticed that VoiceOver only read "Error:, and 1 more item, alert, main" and then stopped. It would be great if we could find a solution for this, but if not, I think we can go with this for now and improve it later.

Screen.Recording.2024-05-14.at.14.03.40.mov

I also checked how WordPress handles this on the login page, and it seems that they use aria-described by to associate the alert message with the input field and auto-focus on the input field when the page is loaded. I think this is a good approach, but I can see that we will need to make some changes to our code to make it work with our current implementation, so I don't think we can do this now. And if we want to do this, we should also consider if we can submit with Ajax directly.

Screenshot 2024-05-14 at 15 28 50

if (notices.length > 0) {
setTimeout(function() {
$(notices[0]).attr('tabindex', '-1').focus();
}, 1000);
Copy link
Member

@chihsuan chihsuan May 14, 2024

Choose a reason for hiding this comment

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

Could you explain why this specific delay is needed? 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I am queuing the focus event at last of the event queue to override any other focus events in case of critical error. In my case, "Skip to content" was being focused just after the error, resulting in the voiceover breaking the message.

I've removed 1000 delay, and just kept the default timeout.

Copy link
Member

Choose a reason for hiding this comment

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

@naman03malhotra Thanks for the explanation! That makes sense. Would you mind adding a comment to the code? That would be helpful for future developers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would you mind adding a comment to the code?

Good suggestion, I will add

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added here: 068a944

@naman03malhotra
Copy link
Contributor Author

naman03malhotra commented May 20, 2024

Thank you @chihsuan for an in-depth review 🙇

However, it doesn't work very well with classic themes such as "StoreFront". I tried a few times and sometimes it reads the alert message, but sometimes it doesn't. (It did focus the alert element.)

Hmm, that's strange, it is working well for me at least on Safari. Check the screencast below

Screen.Recording.2024-05-20.at.21.00.26.mov

Additionally, I tested it on Chrome. I noticed that VoiceOver only read "Error:, and 1 more item, alert, main" and then stopped. It would be great if we could find a solution for this, but if not, I think we can go with this for now and improve it later.

I also observed that issue; it looks like it is a Chrome thing; I tried to fiddle around to find a solution, so it looks like removing role="alert" solves the issue, but it causes problems in other browsers.

Also, from all the testing, it seems like voice-over for Mac is most compatible with Safari, which I think most folks would be using while leveraging accessibility features.

but I can see that we will need to make some changes to our code to make it work with our current implementation, so I don't think we can do this now. And if we want to do this, we should also consider if we can submit with Ajax directly.

+1 to this.

I believe that we can have more robust accessibility with dynamic content submission instead of a full page reload, however that would require more code change.

That said, I believe this change will give some relief to folks who need features to be accessible. Later, we can plan to change our accounts section to submit data using Ajax.

Copy link
Member

@chihsuan chihsuan left a comment

Choose a reason for hiding this comment

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

Thanks for the addressing the feedback! I tested again with safari and it seems to be working fine. 👍

Code looks good to me except for the comment. I'd recommend testing with other browsers on Windows as well but I think this is good to go.

Code looks good to me except for the comment. Pre-approving!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: accessibility The issue/PR is related to accessibility. plugin: woocommerce Issues related to the WooCommerce Core plugin. team: Proton
Projects
None yet
3 participants