| @@ -8,9 +8,9 @@ | ||
| 8 | 8 | /** |
| 9 | 9 | * Render callback for core/tab-list. |
| 10 | 10 | * |
| 11 | 11 | * Injects IAPI directives into the saved button HTML. The buttons already |
| 12 | - * carry color/border/padding styles from save.js; this callback adds | |
| 12 | + * carry color/border/padding styles from save.jsx; this callback adds | |
| 13 | 13 | * tab-specific attributes (id, aria-controls, context) and interactivity |
| 14 | 14 | * directives using data from the tabs-list context. |
| 15 | 15 | * |
| 16 | 16 | * @since 7.1.0 |
| @@ -15,22 +15,27 @@ | ||
| 15 | 15 | * |
| 16 | 16 | * @since 7.1.0 |
| 17 | 17 | * |
| 18 | 18 | * @param array $attributes Block attributes. |
| 19 | - * @param string $content Block content (rendered buttons from save.js). | |
| 19 | + * @param string $content Block content (rendered buttons from save.jsx). | |
| 20 | 20 | * @param \WP_Block $block WP_Block instance. |
| 21 | 21 | * |
| 22 | 22 | * @return string Updated HTML. |
| 23 | 23 | */ |
| 24 | 24 | function gutenberg_block_core_tab_list_render_callback( array $attributes, string $content, \WP_Block $block ): string { |
| 25 | - $tabs_list = $block->context['core/tabs-list'] ?? array(); | |
| 25 | + $tabs_list = $block->context['core/tabs-list'] ?? array(); | |
| 26 | + $aria_label = empty( $attributes['ariaLabel'] ) ? __( 'Tabbed content' ) : wp_strip_all_tags( $attributes['ariaLabel'] ); | |
| 26 | 27 | |
| 28 | + $tag_processor = new WP_HTML_Tag_Processor( $content ); | |
| 29 | + if ( $tag_processor->next_tag( array( 'class_name' => 'wp-block-tab-list' ) ) ) { | |
| 30 | + $tag_processor->set_attribute( 'aria-label', $aria_label ); | |
| 31 | + } | |
| 32 | + | |
| 27 | 33 | if ( empty( $tabs_list ) ) { |
| 28 | - return $content; | |
| 34 | + return $tag_processor->get_updated_html(); | |
| 29 | 35 | } |
| 30 | 36 | |
| 31 | - $tag_processor = new WP_HTML_Tag_Processor( $content ); | |
| 32 | - $tab_index = 0; | |
| 37 | + $tab_index = 0; | |
| 33 | 38 | |
| 34 | 39 | while ( $tag_processor->next_tag( 'button' ) ) { |
| 35 | 40 | $tab_id = $tabs_list[ $tab_index ] ?? null; |
| 36 | 41 | |