Skip to content

Commit bc0b296

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@53051 602fd350-edb4-49c9-b593-d223f7449a82
1 parent c27cc8b commit bc0b296

3 files changed

Lines changed: 24 additions & 8 deletions

File tree

src/wp-content/themes/twentytwenty/assets/js/index.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -678,20 +678,36 @@ twentytwentyDomReady( function() {
678678
/* Toggle an attribute ----------------------- */
679679

680680
function twentytwentyToggleAttribute( element, attribute, trueVal, falseVal ) {
681-
if ( element.classList.contains( 'close-search-toggle' ) ) {
681+
var toggles;
682+
683+
if ( ! element.hasAttribute( attribute ) ) {
682684
return;
683685
}
686+
684687
if ( trueVal === undefined ) {
685688
trueVal = true;
686689
}
687690
if ( falseVal === undefined ) {
688691
falseVal = false;
689692
}
690-
if ( element.getAttribute( attribute ) !== trueVal ) {
691-
element.setAttribute( attribute, trueVal );
692-
} else {
693-
element.setAttribute( attribute, falseVal );
694-
}
693+
694+
/*
695+
* Take into account multiple toggle elements that need their state to be
696+
* synced. For example: the Search toggle buttons for desktop and mobile.
697+
*/
698+
toggles = document.querySelectorAll( '[data-toggle-target="' + element.dataset.toggleTarget + '"]' );
699+
700+
toggles.forEach( function( toggle ) {
701+
if ( ! toggle.hasAttribute( attribute ) ) {
702+
return;
703+
}
704+
705+
if ( toggle.getAttribute( attribute ) !== trueVal ) {
706+
toggle.setAttribute( attribute, trueVal );
707+
} else {
708+
toggle.setAttribute( attribute, falseVal );
709+
}
710+
} );
695711
}
696712

697713
/**

src/wp-content/themes/twentytwenty/template-parts/modal-menu.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<div class="menu-top">
1919

20-
<button class="toggle close-nav-toggle fill-children-current-color" data-toggle-target=".menu-modal" data-toggle-body-class="showing-menu-modal" aria-expanded="false" data-set-focus=".menu-modal">
20+
<button class="toggle close-nav-toggle fill-children-current-color" data-toggle-target=".menu-modal" data-toggle-body-class="showing-menu-modal" data-set-focus=".menu-modal">
2121
<span class="toggle-text"><?php _e( 'Close Menu', 'twentytwenty' ); ?></span>
2222
<?php twentytwenty_the_theme_svg( 'cross' ); ?>
2323
</button><!-- .nav-toggle -->

src/wp-content/themes/twentytwenty/template-parts/modal-search.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
?>
11-
<div class="search-modal cover-modal header-footer-group" data-modal-target-string=".search-modal">
11+
<div class="search-modal cover-modal header-footer-group" data-modal-target-string=".search-modal" role="dialog" aria-modal="true" aria-label="<?php esc_attr_e( 'Search', 'twentytwenty' ); ?>">
1212

1313
<div class="search-modal-inner modal-inner">
1414

0 commit comments

Comments
 (0)