PluginProbe
Gutenberg / 22.9.0
Gutenberg v22.9.0
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / build / scripts / block-library / tab.php

tab.php in Gutenberg 22.9.0, at build/scripts/block-library/tab.php

73 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Tabs Block
4 *
5 * @package WordPress
6 */
7
8 /**
9 * Render callback for core/tab.
10 *
11 * @since 7.0.0
12 *
13 * @param array $attributes Block attributes.
14 * @param string $content Block content.
15 *
16 * @return string Updated HTML.
17 */
18 function gutenberg_block_core_tab_render( array $attributes, string $content ): string {
19 $tag_processor = new WP_HTML_Tag_Processor( $content );
20 $tag_processor->next_tag( array( 'class_name' => 'wp-block-tab' ) );
21 $tab_id = (string) $tag_processor->get_attribute( 'id' );
22 // If no id, generate a unique one
23 if ( empty( $tab_id ) ) {
24 $tab_id = sanitize_title( $attributes['label'] );
25 $tag_processor->set_attribute( 'id', $tab_id );
26 }
27
28 /**
29 * Add interactivity to the tab element.
30 */
31 $tag_processor->set_attribute(
32 'data-wp-interactive',
33 'core/tabs/private'
34 );
35 $tag_processor->set_attribute(
36 'data-wp-context',
37 wp_json_encode(
38 array(
39 'tab' => array(
40 'id' => $tab_id,
41 ),
42 )
43 )
44 );
45
46 /**
47 * Process accessibility and interactivity attributes.
48 */
49 $tag_processor->set_attribute( 'role', 'tabpanel' );
50 $tag_processor->set_attribute( 'aria-labelledby', 'tab__' . $tab_id );
51 $tag_processor->set_attribute( 'data-wp-bind--hidden', '!state.isActiveTab' );
52 $tag_processor->set_attribute( 'tabindex', 0 );
53
54 return (string) $tag_processor->get_updated_html();
55 }
56
57 /**
58 * Registers the `core/tab` block on the server.
59 *
60 * @hook init
61 *
62 * @since 7.0.0
63 */
64 function gutenberg_register_block_core_tab() {
65 register_block_type_from_metadata(
66 __DIR__ . '/tab',
67 array(
68 'render_callback' => 'gutenberg_block_core_tab_render',
69 )
70 );
71 }
72 add_action( 'init', 'gutenberg_register_block_core_tab', 20 );
73