Make WordPress Core


Ignore:
Timestamp:
10/13/2024 07:07:06 PM (14 months ago)
Author:
joedolson
Message:

Administration: A11y: Fix accordion accessibility.

Change accordions in the customizer and the navigation menus to make proper usage of accordion markup patterns. This includes adding missing :focus states, using a button element to control tabbing and interaction, instead of the heading elements, and removing instructional text for screen reader users that was used to compensate for the incorrect markup pattern.

Props afercia, rishishah, kushang78, rcreators, krupajnanda, hmbashar, joedolson.
Fixes #42002.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/wp/customize/controls.js

    r59197 r59224  
    15311531
    15321532            // Expand/Collapse accordion sections on click.
    1533             section.container.find( '.accordion-section-title, .customize-section-back' ).on( 'click keydown', function( event ) {
     1533            section.container.find( '.accordion-section-title button, .customize-section-back' ).on( 'click keydown', function( event ) {
    15341534                if ( api.utils.isKeydownButNotEnterEvent( event ) ) {
    15351535                    return;
     
    16061606                overlay = section.headContainer.closest( '.wp-full-overlay' ),
    16071607                backBtn = content.find( '.customize-section-back' ),
    1608                 sectionTitle = section.headContainer.find( '.accordion-section-title' ).first(),
     1608                sectionTitle = section.headContainer.find( '.accordion-section-title button' ).first(),
    16091609                expand, panel;
    16101610
     
    16161616                    expand = function() {
    16171617                        section._animateChangeExpanded( function() {
    1618                             sectionTitle.attr( 'tabindex', '-1' );
    1619                             backBtn.attr( 'tabindex', '0' );
    1620 
    16211618                            backBtn.trigger( 'focus' );
    16221619                            content.css( 'top', '' );
     
    16641661                }
    16651662                section._animateChangeExpanded( function() {
    1666                     backBtn.attr( 'tabindex', '-1' );
    1667                     sectionTitle.attr( 'tabindex', '0' );
    16681663
    16691664                    sectionTitle.trigger( 'focus' );
     
    27002695                content = section.contentContainer,
    27012696                backBtn = content.find( '.customize-section-back' ),
    2702                 sectionTitle = section.headContainer.find( '.accordion-section-title' ).first(),
     2697                sectionTitle = section.headContainer.find( '.accordion-section-title button' ).first(),
    27032698                body = $( document.body ),
    27042699                expand, panel;
     
    27202715                    expand = function() {
    27212716                        section._animateChangeExpanded( function() {
    2722                             sectionTitle.attr( 'tabindex', '-1' );
    2723                             backBtn.attr( 'tabindex', '0' );
    2724 
    27252717                            backBtn.trigger( 'focus' );
    27262718                            content.css( 'top', '' );
     
    27532745                }
    27542746                section._animateChangeExpanded( function() {
    2755                     backBtn.attr( 'tabindex', '-1' );
    2756                     sectionTitle.attr( 'tabindex', '0' );
    27572747
    27582748                    sectionTitle.trigger( 'focus' );
     
    28442834
    28452835            // Expand/Collapse accordion sections on click.
    2846             panel.headContainer.find( '.accordion-section-title' ).on( 'click keydown', function( event ) {
     2836            panel.headContainer.find( '.accordion-section-title button' ).on( 'click keydown', function( event ) {
    28472837                if ( api.utils.isKeydownButNotEnterEvent( event ) ) {
    28482838                    return;
     
    29482938                overlay = accordionSection.closest( '.wp-full-overlay' ),
    29492939                container = accordionSection.closest( '.wp-full-overlay-sidebar-content' ),
    2950                 topPanel = panel.headContainer.find( '.accordion-section-title' ),
     2940                topPanel = panel.headContainer.find( '.accordion-section-title button' ),
    29512941                backBtn = accordionSection.find( '.customize-panel-back' ),
    29522942                childSections = panel.sections(),
     
    29752965                } else {
    29762966                    panel._animateChangeExpanded( function() {
    2977                         topPanel.attr( 'tabindex', '-1' );
    2978                         backBtn.attr( 'tabindex', '0' );
    2979 
    29802967                        backBtn.trigger( 'focus' );
    29812968                        accordionSection.css( 'top', '' );
     
    29972984                if ( ! skipTransition ) {
    29982985                    panel._animateChangeExpanded( function() {
    2999                         topPanel.attr( 'tabindex', '0' );
    3000                         backBtn.attr( 'tabindex', '-1' );
    30012986
    30022987                        topPanel.focus();
Note: See TracChangeset for help on using the changeset viewer.