@@ -19,12 +19,15 @@ function block_core_accordion_item_render( $attributes, $content ) {
1919 $ p = new WP_HTML_Tag_Processor ( $ content );
2020 $ unique_id = wp_unique_id ( 'accordion-item- ' );
2121
22- // Adds the id to the current accordion group list.
22+ // If the item is open by default,
23+ // add its id to the accordion group's initial context.isOpen list.
2324 if ( $ attributes ['openByDefault ' ] ) {
2425 // phpcs:ignore Gutenberg.CodeAnalysis.ForbiddenFunctionsAndClasses.ForbiddenFunctionCall
2526 gutenberg_block_core_accordion_group_item_ids ( $ unique_id );
2627 }
2728
29+ // Initialize the state of the item on the server using a closure,
30+ // since we need to get derived state based on the current context.
2831 wp_interactivity_state (
2932 'core/accordion ' ,
3033 array (
@@ -43,14 +46,14 @@ function block_core_accordion_item_render( $attributes, $content ) {
4346 $ p ->set_attribute ( 'data-wp-on--click ' , 'actions.toggle ' );
4447 $ p ->set_attribute ( 'aria-controls ' , $ unique_id );
4548 $ p ->set_attribute ( 'data-wp-bind--aria-expanded ' , 'state.isOpen ' );
46- }
4749
48- if ( $ p ->next_tag ( array ( 'class_name ' => 'wp-block-accordion-content ' ) ) ) {
49- $ p ->set_attribute ( 'aria-labelledby ' , $ unique_id );
50- $ p ->set_attribute ( 'data-wp-bind--aria-hidden ' , '!state.isOpen ' );
50+ if ( $ p ->next_tag ( array ( 'class_name ' => 'wp-block-accordion-content ' ) ) ) {
51+ $ p ->set_attribute ( 'aria-labelledby ' , $ unique_id );
52+ $ p ->set_attribute ( 'data-wp-bind--aria-hidden ' , '!state.isOpen ' );
5153
52- // Only modify content if all directives have been set.
53- $ content = $ p ->get_updated_html ();
54+ // Only modify content if all directives have been set.
55+ $ content = $ p ->get_updated_html ();
56+ }
5457 }
5558 }
5659
0 commit comments