diff --git a/lib/experimental/editor-settings.php b/lib/experimental/editor-settings.php index 0fd28025582dde..c7dd5850a505c3 100644 --- a/lib/experimental/editor-settings.php +++ b/lib/experimental/editor-settings.php @@ -95,6 +95,9 @@ function gutenberg_enable_experiments() { if ( $gutenberg_experiments && array_key_exists( 'gutenberg-details-blocks', $gutenberg_experiments ) ) { wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableDetailsBlocks = true', 'before' ); } + if ( $gutenberg_experiments && array_key_exists( 'gutenberg-interactivity-api-navigation-block', $gutenberg_experiments ) ) { + wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableNavigationBlockInteractivity = true', 'before' ); + } if ( $gutenberg_experiments && array_key_exists( 'gutenberg-theme-previews', $gutenberg_experiments ) ) { wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableThemePreviews = true', 'before' ); } diff --git a/lib/experimental/interactivity-api/navigation-block-interactivity.php b/lib/experimental/interactivity-api/navigation-block-interactivity.php new file mode 100644 index 00000000000000..21e1e0381b70ed --- /dev/null +++ b/lib/experimental/interactivity-api/navigation-block-interactivity.php @@ -0,0 +1,240 @@ + + * + * Title + * + * + * + * @param string $w Markup of the navigation block. + * + * @return void + */ +function gutenberg_block_core_navigation_add_directives_to_submenu( $w ) { + while ( $w->next_tag( + array( + 'tag_name' => 'LI', + 'class_name' => 'has-child', + ) + ) ) { + // Add directives to the parent `
  • `. + $w->set_attribute( 'data-wp-context', '{ "core": { "navigation": { "isMenuOpen": false, "overlay": false } } }' ); + + // Add directives to the toggle submenu button. + if ( $w->next_tag( + array( + 'tag_name' => 'BUTTON', + 'class_name' => 'wp-block-navigation-submenu__toggle', + ) + ) ) { + $w->set_attribute( 'data-wp-on.click', 'actions.core.navigation.openMenu' ); + $w->set_attribute( 'data-wp-bind.aria-expanded', 'context.core.navigation.isMenuOpen' ); + $w->set_attribute( 'data-wp-on.keydown', 'actions.core.navigation.handleMenuKeydown' ); + $w->set_attribute( 'data-wp-on.focusout', 'actions.core.navigation.handleMenuFocusout' ); + }; + + // Add directives to the `