From 7b96116f3fb6938a33f157d53e69cdcdec242694 Mon Sep 17 00:00:00 2001 From: joedolson Date: Fri, 1 Apr 2022 17:56:08 +0000 Subject: [PATCH] Twenty Twenty: Fix aria-expanded handling in search toggle. Transform search into a dialog role and fix the handling of aria-expanded to synchronize mobile and desktop buttons. Props utz119, alexstine, mukesh27, hareesh-pillai, sabernhardt, audrasjb, afercia. Fixes #53951. Built from https://develop.svn.wordpress.org/trunk@53051 git-svn-id: http://core.svn.wordpress.org/trunk@52640 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../themes/twentytwenty/assets/js/index.js | 28 +++++++++++++++---- .../template-parts/modal-menu.php | 2 +- .../template-parts/modal-search.php | 2 +- wp-includes/version.php | 2 +- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/wp-content/themes/twentytwenty/assets/js/index.js b/wp-content/themes/twentytwenty/assets/js/index.js index 0a64fd98ba..5daa9eaa7c 100644 --- a/wp-content/themes/twentytwenty/assets/js/index.js +++ b/wp-content/themes/twentytwenty/assets/js/index.js @@ -678,20 +678,36 @@ twentytwentyDomReady( function() { /* Toggle an attribute ----------------------- */ function twentytwentyToggleAttribute( element, attribute, trueVal, falseVal ) { - if ( element.classList.contains( 'close-search-toggle' ) ) { + var toggles; + + if ( ! element.hasAttribute( attribute ) ) { return; } + if ( trueVal === undefined ) { trueVal = true; } if ( falseVal === undefined ) { falseVal = false; } - if ( element.getAttribute( attribute ) !== trueVal ) { - element.setAttribute( attribute, trueVal ); - } else { - element.setAttribute( attribute, falseVal ); - } + + /* + * Take into account multiple toggle elements that need their state to be + * synced. For example: the Search toggle buttons for desktop and mobile. + */ + toggles = document.querySelectorAll( '[data-toggle-target="' + element.dataset.toggleTarget + '"]' ); + + toggles.forEach( function( toggle ) { + if ( ! toggle.hasAttribute( attribute ) ) { + return; + } + + if ( toggle.getAttribute( attribute ) !== trueVal ) { + toggle.setAttribute( attribute, trueVal ); + } else { + toggle.setAttribute( attribute, falseVal ); + } + } ); } /** diff --git a/wp-content/themes/twentytwenty/template-parts/modal-menu.php b/wp-content/themes/twentytwenty/template-parts/modal-menu.php index bd6b08889e..f157f5159b 100644 --- a/wp-content/themes/twentytwenty/template-parts/modal-menu.php +++ b/wp-content/themes/twentytwenty/template-parts/modal-menu.php @@ -17,7 +17,7 @@