From 3dad409c398fcb93d43f6d8ff2198c016f471ccc Mon Sep 17 00:00:00 2001 From: audrasjb Date: Sat, 22 Feb 2025 00:30:22 +0000 Subject: [PATCH] TwentyTwentyOne: Add `aria-controls` attributes to primary sub-menu. On the Twenty Twenty-One theme, this changeset adds `aria-controls` attribute to sub-menu buttons and an `id` to the sub-menu wrapper for additional context on what is being expanded. Props bschneidewind, audrasjb, anandraj346. Fixes #62973. Built from https://develop.svn.wordpress.org/trunk@59856 git-svn-id: http://core.svn.wordpress.org/trunk@59198 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../twentytwentyone/assets/js/primary-navigation.js | 13 +++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/wp-content/themes/twentytwentyone/assets/js/primary-navigation.js b/wp-content/themes/twentytwentyone/assets/js/primary-navigation.js index c53af8268c..8b3739865f 100644 --- a/wp-content/themes/twentytwentyone/assets/js/primary-navigation.js +++ b/wp-content/themes/twentytwentyone/assets/js/primary-navigation.js @@ -120,6 +120,19 @@ function twentytwentyoneExpandSubMenu( el ) { // jshint ignore:line }; } + // Add aria-controls attributes to primary sub-menu. + var subMenus = document.querySelectorAll( '.primary-menu-container .sub-menu' ); + subMenus.forEach( function( subMenu, index ) { + var parentLi = subMenu.closest( 'li.menu-item-has-children' ); + subMenu.id = 'sub-menu-' + ( index + 1 ); + if ( parentLi ) { + var parentLink = parentLi.querySelector( 'button' ); + if ( parentLink ) { + parentLink.setAttribute( 'aria-controls', subMenu.id ); + } + } + } ); + /** * Trap keyboard navigation in the menu modal. * Adapted from Twenty Twenty. diff --git a/wp-includes/version.php b/wp-includes/version.php index 127619abf7..a2981a65f2 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.8-alpha-59855'; +$wp_version = '6.8-alpha-59856'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.