wp/wp-admin/js/accordion.js
changeset 22 8c2e4d02f4ef
parent 18 be944660c56a
--- a/wp/wp-admin/js/accordion.js	Fri Sep 05 18:40:08 2025 +0200
+++ b/wp/wp-admin/js/accordion.js	Fri Sep 05 18:52:52 2025 +0200
@@ -7,18 +7,18 @@
  *
  * <div class="accordion-container">
  *	<div class="accordion-section open">
- *		<h3 class="accordion-section-title"></h3>
- *		<div class="accordion-section-content">
+ *		<h3 class="accordion-section-title"><button type="button" aria-expanded="true" aria-controls="target-1"></button></h3>
+ *		<div class="accordion-section-content" id="target">
  *		</div>
  *	</div>
  *	<div class="accordion-section">
- *		<h3 class="accordion-section-title"></h3>
- *		<div class="accordion-section-content">
+ *		<h3 class="accordion-section-title"><button type="button" aria-expanded="false" aria-controls="target-2"></button></h3>
+ *		<div class="accordion-section-content" id="target-2">
  *		</div>
  *	</div>
  *	<div class="accordion-section">
- *		<h3 class="accordion-section-title"></h3>
- *		<div class="accordion-section-content">
+ *		<h3 class="accordion-section-title"><button type="button" aria-expanded="false" aria-controls="target-3"></button></h3>
+ *		<div class="accordion-section-content" id="target-3">
  *		</div>
  *	</div>
  * </div>
@@ -34,13 +34,7 @@
 	$( function () {
 
 		// Expand/Collapse accordion sections on click.
-		$( '.accordion-container' ).on( 'click keydown', '.accordion-section-title', function( e ) {
-			if ( e.type === 'keydown' && 13 !== e.which ) { // "Return" key.
-				return;
-			}
-
-			e.preventDefault(); // Keep this AFTER the key filter above.
-
+		$( '.accordion-container' ).on( 'click', '.accordion-section-title button', function() {
 			accordionSwitch( $( this ) );
 		});
 
@@ -54,7 +48,6 @@
 	 */
 	function accordionSwitch ( el ) {
 		var section = el.closest( '.accordion-section' ),
-			sectionToggleControl = section.find( '[aria-expanded]' ).first(),
 			container = section.closest( '.accordion-container' ),
 			siblings = container.find( '.open' ),
 			siblingsToggleControl = siblings.find( '[aria-expanded]' ).first(),
@@ -86,8 +79,8 @@
 		}, 150);
 
 		// If there's an element with an aria-expanded attribute, assume it's a toggle control and toggle the aria-expanded value.
-		if ( sectionToggleControl ) {
-			sectionToggleControl.attr( 'aria-expanded', String( sectionToggleControl.attr( 'aria-expanded' ) === 'false' ) );
+		if ( el ) {
+			el.attr( 'aria-expanded', String( el.attr( 'aria-expanded' ) === 'false' ) );
 		}
 	}