Site Health: Improve wp.a11y.speak() notifications.

Improve the experience for screen reader users by removing announcements produced in the Dashboard, simplifying the text to reduce verbosity, and ensuring that messages are spoken in the correct order to match the state of the user interface without repetition.

Props afercia, alexstine.
Fixes #58573.

git-svn-id: https://develop.svn.wordpress.org/trunk@56670 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Joe Dolson
2023-09-24 20:11:59 +00:00
parent 9cec160110
commit 816561d1fd
+34 -5
View File
@@ -225,12 +225,12 @@ jQuery( function( $ ) {
$wrapper.addClass( 'green' ).removeClass( 'orange' );
$progressLabel.text( __( 'Good' ) );
wp.a11y.speak( __( 'All site health tests have finished running. Your site is looking good, and the results are now available on the page.' ) );
announceTestsProgression( 'good' );
} else {
$wrapper.addClass( 'orange' ).removeClass( 'green' );
$progressLabel.text( __( 'Should be improved' ) );
wp.a11y.speak( __( 'All site health tests have finished running. There are items that should be addressed, and the results are now available on the page.' ) );
announceTestsProgression( 'improvable' );
}
if ( isStatusTab ) {
@@ -379,7 +379,7 @@ jQuery( function( $ ) {
// After 3 seconds announce that we're still waiting for directory sizes.
var timeout = window.setTimeout( function() {
wp.a11y.speak( __( 'Please wait...' ) );
announceTestsProgression( 'waiting-for-directory-sizes' );
}, 3000 );
wp.apiRequest( {
@@ -390,7 +390,6 @@ jQuery( function( $ ) {
var delay = ( new Date().getTime() ) - timestamp;
$( '.health-check-wp-paths-sizes.spinner' ).css( 'visibility', 'hidden' );
recalculateProgression();
if ( delay > 3000 ) {
/*
@@ -405,7 +404,7 @@ jQuery( function( $ ) {
}
window.setTimeout( function() {
wp.a11y.speak( __( 'All site health tests have finished running.' ) );
recalculateProgression();
}, delay );
} else {
// Cancel the announcement.
@@ -452,4 +451,34 @@ jQuery( function( $ ) {
$( '.health-check-offscreen-nav-wrapper' ).on( 'click', function() {
$( this ).toggleClass( 'visible' );
} );
/**
* Announces to assistive technologies the tests progression status.
*
* @since 6.4.0
*
* @param {string} type The type of message to be announced.
*
* @return {void}
*/
function announceTestsProgression( type ) {
// Only announce the messages in the Site Health pages.
if ( 'site-health' !== SiteHealth.screen ) {
return;
}
switch ( type ) {
case 'good':
wp.a11y.speak( __( 'All site health tests have finished running. Your site is looking good.' ) );
break;
case 'improvable':
wp.a11y.speak( __( 'All site health tests have finished running. There are items that should be addressed.' ) );
break;
case 'waiting-for-directory-sizes':
wp.a11y.speak( __( 'Running additional tests... please wait.' ) );
break;
default:
return;
}
}
} );