Skip to content

Commit

Permalink
Administration: Switch order of label/checkbox in WP_List_Table.
Browse files Browse the repository at this point in the history
Move the label after the checkbox in `WP_List_Table` instances. Resolve a false positive that will be presented by automated accessibility testing tools. Follow up to [55954].

Props dimitrism, joedolson, sabernhardt, oglekler, marybaum, tobiasbg.
Fixes #58703.

git-svn-id: https://develop.svn.wordpress.org/trunk@56665 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
joedolson committed Sep 22, 2023
1 parent 9608dd5 commit 32ba91e
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 37 deletions.
13 changes: 10 additions & 3 deletions src/wp-admin/css/list-tables.css
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,8 @@ th.sorted.desc:hover .sorting-indicator.asc:before {
position: relative;
}

.check-column .label-covers-full-cell {
.check-column label {
box-sizing: border-box;
width: 100%;
height: 100%;
display: block;
Expand All @@ -579,15 +580,21 @@ th.sorted.desc:hover .sorting-indicator.asc:before {
left: 0;
}

.check-column .label-covers-full-cell + input {
.check-column input {
position: relative;
z-index: 1;
}

.check-column .label-covers-full-cell:hover + input {
.check-column input:where(:not(:disabled)):hover,
.check-column:hover input:where(:not(:disabled)) {
box-shadow: 0 0 0 1px #2271b1;
}

.check-column label:hover,
.check-column input:hover + label {
background: rgba(0, 0, 0, 0.05);
}

.locked-indicator {
display: none;
margin-left: 6px;
Expand Down
4 changes: 2 additions & 2 deletions src/wp-admin/includes/class-wp-comments-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -896,15 +896,15 @@ public function column_cb( $item ) {

if ( $this->user_can ) {
?>
<label class="label-covers-full-cell" for="cb-select-<?php echo $comment->comment_ID; ?>">
<input id="cb-select-<?php echo $comment->comment_ID; ?>" type="checkbox" name="delete_comments[]" value="<?php echo $comment->comment_ID; ?>" />
<label for="cb-select-<?php echo $comment->comment_ID; ?>">
<span class="screen-reader-text">
<?php
/* translators: Hidden accessibility text. */
_e( 'Select comment' );
?>
</span>
</label>
<input id="cb-select-<?php echo $comment->comment_ID; ?>" type="checkbox" name="delete_comments[]" value="<?php echo $comment->comment_ID; ?>" />
<?php
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/wp-admin/includes/class-wp-links-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ public function column_cb( $item ) {
$link = $item;

?>
<label class="label-covers-full-cell" for="cb-select-<?php echo $link->link_id; ?>">
<input type="checkbox" name="linkcheck[]" id="cb-select-<?php echo $link->link_id; ?>" value="<?php echo esc_attr( $link->link_id ); ?>" />
<label for="cb-select-<?php echo $link->link_id; ?>">
<span class="screen-reader-text">
<?php
/* translators: Hidden accessibility text. %s: Link name. */
printf( __( 'Select %s' ), $link->link_name );
?>
</span>
</label>
<input type="checkbox" name="linkcheck[]" id="cb-select-<?php echo $link->link_id; ?>" value="<?php echo esc_attr( $link->link_id ); ?>" />
<?php
}

Expand Down
6 changes: 3 additions & 3 deletions src/wp-admin/includes/class-wp-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -1403,13 +1403,13 @@ public function print_column_headers( $with_id = true ) {

if ( ! empty( $columns['cb'] ) ) {
static $cb_counter = 1;
$columns['cb'] = '<label class="label-covers-full-cell" for="cb-select-all-' . $cb_counter . '">' .
$columns['cb'] = '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />
<label for="cb-select-all-' . $cb_counter . '">' .
'<span class="screen-reader-text">' .
/* translators: Hidden accessibility text. */
__( 'Select All' ) .
'</span>' .
'</label>' .
'<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />';
'</label>';
++$cb_counter;
}

Expand Down
4 changes: 2 additions & 2 deletions src/wp-admin/includes/class-wp-media-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,15 @@ public function column_cb( $item ) {

if ( current_user_can( 'edit_post', $post->ID ) ) {
?>
<label class="label-covers-full-cell" for="cb-select-<?php echo $post->ID; ?>">
<input type="checkbox" name="media[]" id="cb-select-<?php echo $post->ID; ?>" value="<?php echo $post->ID; ?>" />
<label for="cb-select-<?php echo $post->ID; ?>">
<span class="screen-reader-text">
<?php
/* translators: Hidden accessibility text. %s: Attachment title. */
printf( __( 'Select %s' ), _draft_or_post_title() );
?>
</span>
</label>
<input type="checkbox" name="media[]" id="cb-select-<?php echo $post->ID; ?>" value="<?php echo $post->ID; ?>" />
<?php
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/wp-admin/includes/class-wp-ms-sites-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,16 +420,15 @@ public function column_cb( $item ) {
if ( ! is_main_site( $blog['blog_id'] ) ) :
$blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
?>
<label class="label-covers-full-cell" for="blog_<?php echo $blog['blog_id']; ?>">
<input type="checkbox" id="blog_<?php echo $blog['blog_id']; ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ); ?>" />
<label for="blog_<?php echo $blog['blog_id']; ?>">
<span class="screen-reader-text">
<?php
/* translators: %s: Site URL. */
printf( __( 'Select %s' ), $blogname );
?>
</span>
</label>
<input type="checkbox" id="blog_<?php echo $blog['blog_id']; ?>" name="allblogs[]"
value="<?php echo esc_attr( $blog['blog_id'] ); ?>" />
<?php
endif;
}
Expand Down
4 changes: 2 additions & 2 deletions src/wp-admin/includes/class-wp-ms-themes-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,8 @@ public function column_cb( $item ) {

$checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) );
?>
<label class="label-covers-full-cell" for="<?php echo $checkbox_id; ?>" >
<input type="checkbox" name="checked[]" value="<?php echo esc_attr( $theme->get_stylesheet() ); ?>" id="<?php echo $checkbox_id; ?>" />
<label for="<?php echo $checkbox_id; ?>" >
<span class="screen-reader-text">
<?php
printf(
Expand All @@ -524,7 +525,6 @@ public function column_cb( $item ) {
?>
</span>
</label>
<input type="checkbox" name="checked[]" value="<?php echo esc_attr( $theme->get_stylesheet() ); ?>" id="<?php echo $checkbox_id; ?>" />
<?php
}

Expand Down
4 changes: 2 additions & 2 deletions src/wp-admin/includes/class-wp-ms-users-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,15 @@ public function column_cb( $item ) {
return;
}
?>
<label class="label-covers-full-cell" for="blog_<?php echo $user->ID; ?>">
<input type="checkbox" id="blog_<?php echo $user->ID; ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ); ?>" />
<label for="blog_<?php echo $user->ID; ?>">
<span class="screen-reader-text">
<?php
/* translators: Hidden accessibility text. %s: User login. */
printf( __( 'Select %s' ), $user->user_login );
?>
</span>
</label>
<input type="checkbox" id="blog_<?php echo $user->ID; ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ); ?>" />
<?php
}

Expand Down
8 changes: 4 additions & 4 deletions src/wp-admin/includes/class-wp-plugins-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -993,12 +993,12 @@ public function single_row( $item ) {
$checkbox = '';
} else {
$checkbox = sprintf(
'<label class="label-covers-full-cell" for="%1$s"><span class="screen-reader-text">%2$s</span></label>' .
'<input type="checkbox" name="checked[]" value="%3$s" id="%1$s" />',
'<input type="checkbox" name="checked[]" value="%1$s" id="%2$s" />' .
'<label for="%2$s"><span class="screen-reader-text">%3$s</span></label>',
esc_attr( $plugin_file ),
$checkbox_id,
/* translators: Hidden accessibility text. %s: Plugin name. */
sprintf( __( 'Select %s' ), $plugin_data['Name'] ),
esc_attr( $plugin_file )
sprintf( __( 'Select %s' ), $plugin_data['Name'] )
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/wp-admin/includes/class-wp-posts-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -1034,15 +1034,15 @@ public function column_cb( $item ) {
*/
if ( apply_filters( 'wp_list_table_show_post_checkbox', $show, $post ) ) :
?>
<label class="label-covers-full-cell" for="cb-select-<?php the_ID(); ?>">
<input id="cb-select-<?php the_ID(); ?>" type="checkbox" name="post[]" value="<?php the_ID(); ?>" />
<label for="cb-select-<?php the_ID(); ?>">
<span class="screen-reader-text">
<?php
/* translators: %s: Post title. */
printf( __( 'Select %s' ), _draft_or_post_title() );
?>
</span>
</label>
<input id="cb-select-<?php the_ID(); ?>" type="checkbox" name="post[]" value="<?php the_ID(); ?>" />
<div class="locked-indicator">
<span class="locked-indicator-icon" aria-hidden="true"></span>
<span class="screen-reader-text">
Expand Down
4 changes: 2 additions & 2 deletions src/wp-admin/includes/class-wp-privacy-requests-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ public function prepare_items() {
*/
public function column_cb( $item ) {
return sprintf(
'<label class="label-covers-full-cell" for="requester_%1$s"><span class="screen-reader-text">%2$s</span></label>' .
'<input type="checkbox" name="request_id[]" id="requester_%1$s" value="%1$s" /><span class="spinner"></span>',
'<input type="checkbox" name="request_id[]" id="requester_%1$s" value="%1$s" />' .
'<label for="requester_%1$s"><span class="screen-reader-text">%2$s</span></label><span class="spinner"></span>',
esc_attr( $item->ID ),
/* translators: Hidden accessibility text. %s: Email address. */
sprintf( __( 'Select %s' ), $item->email )
Expand Down
4 changes: 2 additions & 2 deletions src/wp-admin/includes/class-wp-terms-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ public function column_cb( $item ) {

if ( current_user_can( 'delete_term', $tag->term_id ) ) {
return sprintf(
'<label class="label-covers-full-cell" for="cb-select-%1$s"><span class="screen-reader-text">%2$s</span></label>' .
'<input type="checkbox" name="delete_tags[]" value="%1$s" id="cb-select-%1$s" />',
'<input type="checkbox" name="delete_tags[]" value="%1$s" id="cb-select-%1$s" />' .
'<label for="cb-select-%1$s"><span class="screen-reader-text">%2$s</span></label>',
$tag->term_id,
/* translators: Hidden accessibility text. %s: Taxonomy term name. */
sprintf( __( 'Select %s' ), $tag->name )
Expand Down
8 changes: 4 additions & 4 deletions src/wp-admin/includes/class-wp-users-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,12 +524,12 @@ public function single_row( $user_object, $style = '', $role = '', $numposts = 0

// Set up the checkbox (because the user is editable, otherwise it's empty).
$checkbox = sprintf(
'<label class="label-covers-full-cell" for="user_%1$s"><span class="screen-reader-text">%2$s</span></label>' .
'<input type="checkbox" name="users[]" id="user_%1$s" class="%3$s" value="%1$s" />',
'<input type="checkbox" name="users[]" id="user_%1$s" class="%2$s" value="%1$s" />' .
'<label for="user_%1$s"><span class="screen-reader-text">%3$s</span></label>',
$user_object->ID,
$role_classes,
/* translators: Hidden accessibility text. %s: User login. */
sprintf( __( 'Select %s' ), $user_object->user_login ),
$role_classes
sprintf( __( 'Select %s' ), $user_object->user_login )
);

} else {
Expand Down
8 changes: 4 additions & 4 deletions src/wp-admin/update-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,15 +582,15 @@ function list_plugin_updates() {
<tr>
<td class="check-column">
<?php if ( $compatible_php ) : ?>
<label for="<?php echo $checkbox_id; ?>" class="label-covers-full-cell">
<input type="checkbox" name="checked[]" id="<?php echo $checkbox_id; ?>" value="<?php echo esc_attr( $plugin_file ); ?>" />
<label for="<?php echo $checkbox_id; ?>">
<span class="screen-reader-text">
<?php
/* translators: Hidden accessibility text. %s: Plugin name. */
printf( __( 'Select %s' ), $plugin_data->Name );
?>
</span>
</label>
<input type="checkbox" name="checked[]" id="<?php echo $checkbox_id; ?>" value="<?php echo esc_attr( $plugin_file ); ?>" />
<?php endif; ?>
</td>
<td class="plugin-title"><p>
Expand Down Expand Up @@ -760,15 +760,15 @@ function list_theme_updates() {
<tr>
<td class="check-column">
<?php if ( $compatible_wp && $compatible_php ) : ?>
<label for="<?php echo $checkbox_id; ?>" class="label-covers-full-cell">
<input type="checkbox" name="checked[]" id="<?php echo $checkbox_id; ?>" value="<?php echo esc_attr( $stylesheet ); ?>" />
<label for="<?php echo $checkbox_id; ?>">
<span class="screen-reader-text">
<?php
/* translators: Hidden accessibility text. %s: Theme name. */
printf( __( 'Select %s' ), $theme->display( 'Name' ) );
?>
</span>
</label>
<input type="checkbox" name="checked[]" id="<?php echo $checkbox_id; ?>" value="<?php echo esc_attr( $stylesheet ); ?>" />
<?php endif; ?>
</td>
<td class="plugin-title"><p>
Expand Down

0 comments on commit 32ba91e

Please sign in to comment.