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

Add ARIA attributes to alerts and status bars (fix #1637) #1675

Merged
merged 6 commits into from Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions assets/dist/mix-manifest.json
@@ -1,5 +1,5 @@
{
"/scripts/a11y.js": "/scripts/a11y.js?id=f0993aaabbea8a79233b",
"/scripts/a11y.js": "/scripts/a11y.js?id=d41e757e292e7d6c5240",
"/scripts/anchor.js": "/scripts/anchor.js?id=aafffcd9fd35558755fa",
"/styles/catalog.css": "/styles/catalog.css?id=5592c3bde401d0205d10",
"/styles/colors-pb.css": "/styles/colors-pb.css?id=453776ab723bb7b7a9b8",
Expand Down Expand Up @@ -50,4 +50,4 @@
"/scripts/select2.js": "/scripts/select2.js?id=e66208e306a3e3b57128",
"/scripts/sidr.js": "/scripts/sidr.js?id=32495427b04ceeab5376",
"/scripts/table.js": "/scripts/table.js?id=f76268f8f2e9c0e802ff"
}
}
2 changes: 1 addition & 1 deletion assets/dist/scripts/a11y.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions assets/src/scripts/a11y.js
Expand Up @@ -7,6 +7,16 @@ document.addEventListener( 'DOMContentLoaded', function () {
}
}

addAttribute( 'table.wp-list-table th', 'role', 'columnheader' );
// <table> output by do_settings_sections() should have a role="none" attribute
// https://core.trac.wordpress.org/ticket/46899
addAttribute( 'table.form-table', 'role', 'none' );
} )

// WP_List_Table table headers are missing `role=`columnheader` for accessibility
// https://core.trac.wordpress.org/ticket/46977
addAttribute( 'table.wp-list-table th', 'role', 'columnheader' );

// Add attributes to make status and alert bars accessible
addAttribute( 'div.updated', 'role', 'status' );
addAttribute( 'div.notice', 'role', 'status' );
addAttribute( 'div.error', 'role', 'alert' );
} );
6 changes: 3 additions & 3 deletions compatibility.php
Expand Up @@ -165,7 +165,7 @@ function _pb_copy_autoloader() {
*/
function _pb_minimum_php() {
global $pb_minimum_php;
echo '<div id="message" class="error fade"><p>';
echo '<div id="message" role="alert" class="error fade"><p>';
printf(
esc_attr__( 'Pressbooks will not work with your version of PHP. Pressbooks requires PHP version %s or greater. Please upgrade PHP if you would like to use Pressbooks.', 'pressbooks' ),
esc_attr( $pb_minimum_php )
Expand All @@ -178,7 +178,7 @@ function _pb_minimum_php() {
*/
function _pb_minimum_wp() {
global $pb_minimum_wp;
echo '<div id="message" class="error fade"><p>';
echo '<div id="message" role="alert" class="error fade"><p>';
printf(
esc_attr__( 'Pressbooks will not work with your version of WordPress. Pressbooks requires a dedicated install of WordPress Multisite, version %s or greater. Please upgrade WordPress if you would like to use Pressbooks.', 'pressbooks' ),
esc_attr( $pb_minimum_wp )
Expand All @@ -190,7 +190,7 @@ function _pb_minimum_wp() {
* Echo message about Pressbooks not active
*/
function _pb_disabled() {
echo '<div id="message" class="error fade"><p>';
echo '<div id="message" role="alert" class="error fade"><p>';
_e( 'The Pressbooks plugin is inactive, but you have active plugins that require Pressbooks. This is causing errors. Please go to the Plugins page, and activate Pressbooks.', 'pressbooks' );
echo '</p></div>';
}
2 changes: 1 addition & 1 deletion inc/admin/analytics/namespace.php
Expand Up @@ -181,7 +181,7 @@ function display_network_analytics_settings() {
delete_site_option( 'ga_mu_site_specific_allowed' );
}
?>
<div id="message" class="updated notice is-dismissible"><p><strong><?php _e( 'Settings saved.', 'pressbooks' ); ?></strong></div>
<div id="message" role="status" class="updated notice is-dismissible"><p><strong><?php _e( 'Settings saved.', 'pressbooks' ); ?></strong></div>
<?php
}
}
Expand Down
4 changes: 2 additions & 2 deletions inc/admin/laf/namespace.php
Expand Up @@ -1339,14 +1339,14 @@ function admin_notices() {
// Print the error(s).
$errors_to_print = \Pressbooks\get_all_errors();
foreach ( $errors_to_print as $msg ) {
echo '<div class="error"><p>' . $msg . '</p></div>';
echo '<div class="error" role="alert"><p>' . $msg . '</p></div>';
}
\Pressbooks\flush_all_errors();

// Print the notice(s).
$notices_to_print = \Pressbooks\get_all_notices();
foreach ( $notices_to_print as $msg ) {
echo '<div class="updated"><p>' . $msg . '</p></div>';
echo '<div class="updated" role="status"><p>' . $msg . '</p></div>';
}
\Pressbooks\flush_all_notices();
}
Expand Down
2 changes: 1 addition & 1 deletion inc/admin/network/class-sharingandprivacyoptions.php
Expand Up @@ -126,7 +126,7 @@ function render() {
}
update_site_option( $_option, $options );
?>
<div id="message" class="updated notice is-dismissible"><p><strong><?php _e( 'Settings saved.', 'pressbooks' ); ?></strong></div>
<div id="message" role="status" class="updated notice is-dismissible"><p><strong><?php _e( 'Settings saved.', 'pressbooks' ); ?></strong></div>
<?php
}
}
Expand Down
2 changes: 1 addition & 1 deletion inc/modules/export/namespace.php
Expand Up @@ -89,7 +89,7 @@ function dependency_errors_msg() {
$formats = implode( ', ', $dependency_errors );
$pos = strrpos( $formats, ', ' );
$dependency_errors_msg = sprintf(
'<div class="error"><p>%s</p></div>',
'<div class="error" role="alert"><p>%s</p></div>',
sprintf(
__( 'Some dependencies for %1$s exports could not be found. Please verify that you have completed the <a href="%2$s">installation instructions</a>.', 'pressbooks' ),
( $pos ) ? substr_replace( $formats, ', ' . __( 'and', 'pressbooks' ) . ' ', $pos, strlen( ', ' ) ) : $formats,
Expand Down
2 changes: 1 addition & 1 deletion inc/modules/searchandreplace/class-searchandreplace.php
Expand Up @@ -138,7 +138,7 @@ public function adminScreen() {
$this->renderError( $results );
} elseif ( isset( $_POST['replace_and_save'] ) ) {
?>
<div class="updated" id="message" onclick="this.parentNode.removeChild (this)">
<div class="updated" id="message" role="status" onclick="this.parentNode.removeChild (this)">
<p><?php printf( _n( '%d occurrence replaced.', '%d occurrences replaced.', count( $results ) ), count( $results ) ); ?></p>
</div>
<?php
Expand Down
2 changes: 1 addition & 1 deletion inc/theme/namespace.php
Expand Up @@ -132,7 +132,7 @@ function migrate_book_themes() {
add_action(
'admin_notices', function () {
/* translators: 1: URL to Luther theme */
echo '<div id="message" class="error fade"><p>' . sprintf(
echo '<div id="message" role="alert" class="error fade"><p>' . sprintf(
__( 'Luther has been replaced with McLuhan as Pressbooks’ default book theme. To continue using Luther for your book, please ensure that the standalone <a href="%1$s">Luther theme</a> is installed and network activated.', 'pressbooks' ),
'https://github.com/pressbooks/pressbooks-luther/'
) . '</p></div>';
Expand Down
2 changes: 1 addition & 1 deletion pressbooks.php
Expand Up @@ -83,7 +83,7 @@ function _pb_default_book_theme() {
if ( ! function_exists( 'pb_meets_minimum_requirements' ) && ! @include_once( PB_PLUGIN_DIR . 'compatibility.php' ) ) { // @codingStandardsIgnoreLine
return add_action(
'admin_notices', function () {
echo '<div id="message" class="error fade"><p>' . __( 'Cannot find Pressbooks install.', 'pressbooks' ) . '</p></div>';
echo '<div id="message" role="alert" class="error fade"><p>' . __( 'Cannot find Pressbooks install.', 'pressbooks' ) . '</p></div>';
}
);
} elseif ( ! pb_meets_minimum_requirements() ) {
Expand Down
2 changes: 1 addition & 1 deletion symbionts/pressbooks-latex/pb-latex-admin.php
Expand Up @@ -123,7 +123,7 @@ function testImage() {

if ( is_wp_error( $url ) ) {
$code = $url->get_error_code();
$message = '<div class="error"><p>' . $url->get_error_message() . "</p></div>\n";
$message = '<div class="error" role="alert"><p>' . $url->get_error_message() . "</p></div>\n";
echo $message;
} else {
$alt = esc_attr( __( 'Test Image', 'pressbooks' ) );
Expand Down
2 changes: 1 addition & 1 deletion templates/admin/covergenerator.php
Expand Up @@ -47,7 +47,7 @@
if ( ! empty( $dependency_messages ) ) {
$formats = implode( ', ', $dependency_messages );
printf(
'<div class="error"><p>%s</p></div>',
'<div class="error" role="alert"><p>%s</p></div>',
sprintf(
__( 'Some dependencies for %1$s exports could not be found. Please verify that you have completed the <a href="%2$s">installation instructions</a>.', 'pressbooks' ),
( $pos = strrpos( $formats, ', ' ) ) ? substr_replace( $formats, ', ' . __( 'and', 'pressbooks' ) . ' ', $pos, strlen( ', ' ) ) : $formats,
Expand Down
2 changes: 1 addition & 1 deletion templates/admin/custom-styles.php
Expand Up @@ -30,7 +30,7 @@

if ( ! empty( $_GET['custom_styles_error'] ) ) {
// Conversion failed
printf( '<div class="error">%s</div>', __( 'Error: Something went wrong. See logs for more details.', 'pressbooks' ) );
printf( '<div class="error" role="alert">%s</div>', __( 'Error: Something went wrong. See logs for more details.', 'pressbooks' ) );
}

?>
Expand Down
2 changes: 1 addition & 1 deletion templates/admin/dashboard.php
Expand Up @@ -25,7 +25,7 @@
}

update_site_option( 'pressbooks_dashboard_feed', $options ); ?>
<div id="message" class="updated notice is-dismissible"><p><strong><?php _e( 'Settings saved.', 'pressbooks-oauth' ); ?></strong></div>
<div id="message" role="status" class="updated notice is-dismissible"><p><strong><?php _e( 'Settings saved.', 'pressbooks-oauth' ); ?></strong></div>
<?php }
} ?>

Expand Down
2 changes: 1 addition & 1 deletion templates/admin/export.php
Expand Up @@ -107,7 +107,7 @@
if ( ! empty( $dependency_messages ) ) {
$formats = implode( ', ', $dependency_messages );
printf(
'<div class="error"><p>%s</p></div>',
'<div class="error" role="alert"><p>%s</p></div>',
sprintf(
__( 'Some dependencies for %1$s exports could not be found. Please verify that you have completed the <a href="%2$s">installation instructions</a>.', 'pressbooks' ),
( $pos = strrpos( $formats, ', ' ) ) ? substr_replace( $formats, ', ' . __( 'and', 'pressbooks' ) . ' ', $pos, strlen( ', ' ) ) : $formats,
Expand Down
6 changes: 3 additions & 3 deletions tests/test-admin-laf.php
Expand Up @@ -171,7 +171,7 @@ function test_admin_notices() {
ob_start();
\Pressbooks\Admin\Laf\admin_notices();
$buffer = ob_get_clean();
$this->assertEquals( '<div class="error"><p>One</p></div><div class="error"><p>Two</p></div><div class="updated"><p>Three</p></div><div class="updated"><p>Four</p></div>', $buffer );
$this->assertEquals( '<div class="error" role="alert"><p>One</p></div><div class="error" role="alert"><p>Two</p></div><div class="updated" role="status"><p>Three</p></div><div class="updated" role="status"><p>Four</p></div>', $buffer );

$_SESSION['pb_errors'][] = 'One';
$_SESSION['pb_errors'][] = 'Two';
Expand All @@ -182,7 +182,7 @@ function test_admin_notices() {
ob_start();
\Pressbooks\Admin\Laf\admin_notices();
$buffer = ob_get_clean();
$this->assertEquals( '<div class="error"><p>One</p></div><div class="error"><p>Two</p></div><div class="error"><p>Three</p></div><div class="error"><p>Four</p></div><div class="updated"><p>Five</p></div><div class="updated"><p>Six</p></div><div class="updated"><p>Seven</p></div><div class="updated"><p>Eight</p></div>', $buffer );
$this->assertEquals( '<div class="error" role="alert"><p>One</p></div><div class="error" role="alert"><p>Two</p></div><div class="error" role="alert"><p>Three</p></div><div class="error" role="alert"><p>Four</p></div><div class="updated" role="status"><p>Five</p></div><div class="updated" role="status"><p>Six</p></div><div class="updated" role="status"><p>Seven</p></div><div class="updated" role="status"><p>Eight</p></div>', $buffer );

\Pressbooks\add_error( 'A' );
\Pressbooks\add_error( 'B' );
Expand All @@ -191,7 +191,7 @@ function test_admin_notices() {
ob_start();
\Pressbooks\Admin\Laf\admin_notices();
$buffer = ob_get_clean();
$this->assertEquals( '<div class="error"><p>A</p></div><div class="error"><p>B</p></div><div class="updated"><p>C</p></div><div class="updated"><p>D</p></div>', $buffer );
$this->assertEquals( '<div class="error" role="alert"><p>A</p></div><div class="error" role="alert"><p>B</p></div><div class="updated" role="status"><p>C</p></div><div class="updated" role="status"><p>D</p></div>', $buffer );

ob_start();
\Pressbooks\Admin\Laf\admin_notices();
Expand Down