Make WordPress Core

Opened 8 months ago

Closed 5 months ago

Last modified 5 months ago

#55537 closed enhancement (fixed)

Pair wpAjax admin notices with accessible audible messages

Reported by: afercia's profile afercia Owned by: joedolson's profile joedolson
Milestone: 6.1 Priority: normal
Severity: normal Version:
Component: Administration Keywords: has-patch commit
Focuses: accessibility, javascript Cc:

Description (last modified by afercia)

Splitting this out from #47018.

Amongst other things, the window.wpAjax response takes care of displaying success / error admin notices on some pages. In [52170] a couple of these notices were paired with accessible audible messages via wp.a11y.speak.

There are a few more notices that can benefit from the same audible messages, which are typically the responses triggered when wp_die() is used.

Attachments (2)

55537.diff (2.3 KB) - added by afercia 8 months ago.
55537.2.diff (1.6 KB) - added by afercia 8 months ago.

Download all attachments as: .zip

Change History (14)

@afercia
8 months ago

#1 @afercia
8 months ago

  • Keywords has-patch needs-testing added

55537.diff adds accessible audible messages to three more cases in ajax-response.js where admin notices are displayed, so that the visual notices are paired with audible messages.

Following the code in wpAjax.parseAjaxResponse, see https://core.trac.wordpress.org/browser/trunk/src/js/_enqueues/lib/ajax-response.js?rev=52672&marks=20-67#L18

It first checks whether it's a WP_Ajax_Response xml response, handles the response and returns it. After that, there are 3 more cases:

  • isNaN(x): the response is not a number. Rather, it's a string. Typically, a custom message passed to wp_die() e.g. wp_die( __( 'Some error message' ) ).
  • -1 === x: this is when wp_die( -1 ) is used and it's associated with the default message 'Sorry, you are not allowed to do that.'.
  • 0 === x: this is when wp_die( 0 ) is used and it's associated with the default message 'Something went wrong.'.

Worth noting that in all these three cases, the existing code already displays some text in an admin notice.

This patch just uses the same text displayed in the admin notice to trigger an audible message for screen reader users via wp.a11y.speak().

Additionally:

  • Adds a missing script dependency. Note that this is tracked also in #47018.
  • Updates the CSS classes for the admin notices. error and updated are legacy classes and should not be used any longer. Since a few years, the admin notices use a new pattern e.g. notice notice-error, notice notice-success, etc.

To test:
I can't think of an easy way to test this other than altering the code. For example:

  • In the wp_ajax_add_tag() function, before the creation of the WP_Ajax_Response instance, add the following code: wp_die( -1 );
  • Go to the Categories or Tags page.
  • Submit the form.
  • Check an admin notice with text 'Sorry, you are not allowed to do that.' is displayed at the top of the page.
  • Use your browser's dev tools inspector and check the same text is in the ARIA live region with id a11y-speak-polite.
  • Change wp_die( -1 ); to wp_die( 0 ); and repeat the test. The message text will be 'Something went wrong.'.
  • Change wp_die( 0 ); to wp_die( __( 'My custom message' ) ); and repeat the test. Of course, the message text will be 'My custom message'.

This ticket was mentioned in Slack in #accessibility by ryokuhi. View the logs.


8 months ago

#3 @ryokuhi
8 months ago

  • Milestone changed from Awaiting Review to 6.1

We reviewed this ticket today during the Accessibility Team's bug-scrub.
As the ticket seems to be already in good shape, we decided to milestone it for 6.1.

#4 @alexstine
8 months ago

  • Keywords needs-refresh added; needs-testing removed

The patch no longer applies. I will try to fix it if no one gets to it first.

@afercia
8 months ago

#5 @afercia
8 months ago

  • Description modified (diff)
  • Keywords needs-testing added; needs-refresh removed

Thanks @alexstine.
I went ahead and refreshed the patch against latest trunk. See 55537.2.diff

#6 @alexstine
7 months ago

@afercia The patch is working great for me. All cases seem fine. Think this could be marked early for 6.1?

#7 @afercia
7 months ago

@alexstine thanks for testing. I'd defer the decision to the a11y team (I don't have much time to attend the meetings, sorry).

This ticket was mentioned in Slack in #accessibility by ryokuhi. View the logs.


5 months ago

#9 @joedolson
5 months ago

  • Owner set to joedolson
  • Status changed from new to accepted

#10 @joedolson
5 months ago

  • Keywords commit added; needs-testing removed

Tested with VoiceOver/Safari and JAWS/Chrome, JAWS/Firefox. Works as expected; marking for commit.

#11 @joedolson
5 months ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 53709:

(The changeset message doesn't reference this ticket)

#12 @joedolson
5 months ago

Marked the wrong ticket as fixed in the changeset; it should have fixed this ticket, instead. Thus the odd changeset. I should have reverted it, but I didn't notice it for several days. That's 100% on me.

Note: See TracTickets for help on using tickets.