From 816561d1fdf48d6d26150404067b3d8ee7588789 Mon Sep 17 00:00:00 2001 From: Joe Dolson Date: Sun, 24 Sep 2023 20:11:59 +0000 Subject: [PATCH] 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 --- src/js/_enqueues/admin/site-health.js | 39 +++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/js/_enqueues/admin/site-health.js b/src/js/_enqueues/admin/site-health.js index 893ca0c462..5b59771836 100644 --- a/src/js/_enqueues/admin/site-health.js +++ b/src/js/_enqueues/admin/site-health.js @@ -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; + } + } } );