Make WordPress Core

Changeset 61616


Ignore:
Timestamp:
02/12/2026 01:50:20 AM (8 months ago)
Author:
joedolson
Message:

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.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/wp/media/editor.js

    r48650 r61616  
    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                }
  • trunk/src/wp-admin/includes/post.php

    r61463 r61616  
    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
    … …  
    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        }
Note: See TracChangeset for help on using the changeset viewer.