Skip to content

Commit cd290e3

Browse files
committed
Editor: A11y: Fix featured image control naming.
The controls to set and remove a featured image in the Classic Editor use a link with no attributes to identify purpose. Triggering a modal dialog should be done using a button with proper identification. Add `role="button"`, `aria-haspopup="dialog"`, and `aria-controls` attributes to give users appropriate information about the control behavior. Add keypress handlers for button-specific keyboard events. Does not use a `button` element to avoid interfering with style customizations. Props alh0319, joedolson, mukesh27, huzaifaalmesbah. Fixes #63980. git-svn-id: https://develop.svn.wordpress.org/trunk@61616 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 259d1f9 commit cd290e3

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

src/js/_enqueues/wp/media/editor.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -703,15 +703,19 @@
703703
* Update the featured image id when the 'remove' link is clicked.
704704
*/
705705
init: function() {
706-
$('#postimagediv').on( 'click', '#set-post-thumbnail', function( event ) {
707-
event.preventDefault();
708-
// Stop propagation to prevent thickbox from activating.
709-
event.stopPropagation();
710-
711-
wp.media.featuredImage.frame().open();
712-
}).on( 'click', '#remove-post-thumbnail', function() {
713-
wp.media.featuredImage.remove();
714-
return false;
706+
$('#postimagediv').on( 'click keyup keydown', '#set-post-thumbnail', function( event ) {
707+
if ( ( event.type === 'keyup' && event.key === ' ' ) || ( event.type === 'keydown' && event.key === 'Enter' ) || event.type === 'click' ) {
708+
event.preventDefault();
709+
// Stop propagation to prevent thickbox from activating.
710+
event.stopPropagation();
711+
712+
wp.media.featuredImage.frame().open();
713+
}
714+
}).on( 'click keyup keydown', '#remove-post-thumbnail', function( event ) {
715+
if ( ( event.type === 'keyup' && event.key === ' ' ) || ( event.type === 'keydown' && event.key === 'Enter' ) || event.type === 'click' ) {
716+
wp.media.featuredImage.remove();
717+
return false;
718+
}
715719
});
716720
}
717721
};

src/wp-admin/includes/post.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,7 @@ function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) {
16441644

16451645
$post = get_post( $post );
16461646
$post_type_object = get_post_type_object( $post->post_type );
1647-
$set_thumbnail_link = '<p class="hide-if-no-js"><a href="%s" id="set-post-thumbnail"%s class="thickbox">%s</a></p>';
1647+
$set_thumbnail_link = '<p class="hide-if-no-js"><a href="%s" id="set-post-thumbnail"%s class="thickbox" role="button" aria-haspopup="dialog" aria-controls="wp-media-modal">%s</a></p>';
16481648
$upload_iframe_src = get_upload_iframe_src( 'image', $post->ID );
16491649

16501650
$content = sprintf(
@@ -1683,7 +1683,7 @@ function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) {
16831683
$thumbnail_html
16841684
);
16851685
$content .= '<p class="hide-if-no-js howto" id="set-post-thumbnail-desc">' . __( 'Click the image to edit or update' ) . '</p>';
1686-
$content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail">' . esc_html( $post_type_object->labels->remove_featured_image ) . '</a></p>';
1686+
$content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail" role="button">' . esc_html( $post_type_object->labels->remove_featured_image ) . '</a></p>';
16871687
}
16881688
}
16891689

0 commit comments

Comments
 (0)