| @@ -21,12 +21,12 @@ | ||
| 21 | 21 | |
| 22 | 22 | static $tab_counters = array(); |
| 23 | 23 | |
| 24 | 24 | if ( ! isset( $tab_counters[ $tabs_id ] ) ) { |
| 25 | - $tab_counters[ $tabs_id ] = 0; | |
| 25 | + $tab_counters[ $tabs_id ] = 1; | |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - $tab_index = $tab_counters[ $tabs_id ]; | |
| 28 | + $tab_number = $tab_counters[ $tabs_id ]; | |
| 29 | 29 | ++$tab_counters[ $tabs_id ]; |
| 30 | 30 | |
| 31 | 31 | $tag_processor = new WP_HTML_Tag_Processor( $content ); |
| 32 | 32 | $tag_processor->next_tag( array( 'class_name' => 'wp-block-tab-panel' ) ); |
| @@ -35,15 +35,24 @@ | ||
| 35 | 35 | // the generated position-based ID. |
| 36 | 36 | $tab_id = (string) $tag_processor->get_attribute( 'id' ); |
| 37 | 37 | if ( empty( $tab_id ) ) { |
| 38 | 38 | $tab_id = ! empty( $tabs_id ) |
| 39 | - ? $tabs_id . '-tab-' . $tab_index | |
| 40 | - : 'tab-' . $tab_index; | |
| 39 | + ? $tabs_id . '-tab-' . $tab_number | |
| 40 | + : 'tab-' . $tab_number; | |
| 41 | 41 | $tag_processor->set_attribute( 'id', $tab_id ); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | $tag_processor->set_attribute( 'aria-labelledby', 'tab__' . $tab_id ); |
| 45 | - $tag_processor->set_attribute( 'data-wp-bind--hidden', '!state.isActiveTab' ); | |
| 45 | + | |
| 46 | + /* | |
| 47 | + * Hiding a panel is left to the client, which is why `hidden` is bound to a | |
| 48 | + * state getter the server cannot resolve rather than set here: a visitor | |
| 49 | + * whose browser never runs the block's script is then given the content of | |
| 50 | + * every panel instead of none of it. `core/accordion` works the same way. | |
| 51 | + */ | |
| 52 | + $tag_processor->set_attribute( 'data-wp-bind--hidden', 'state.isHidden' ); | |
| 53 | + $tag_processor->set_attribute( 'data-wp-bind--tabindex', 'state.tabIndexAttribute' ); | |
| 54 | + $tag_processor->set_attribute( 'data-wp-on--beforematch', 'actions.handleBeforeMatch' ); | |
| 46 | 55 | |
| 47 | 56 | return (string) $tag_processor->get_updated_html(); |
| 48 | 57 | } |
| 49 | 58 | |