Description
In #74653, the openSubmenusOnClick key was removed from the usesContext array in packages/block-library/src/navigation-submenu/block.json.
While internal rendering (via inner_blocks) appears to handle context propagation, this removal breaks plugins that instantiate the block programmatically using new WP_Block( $attributes, $context ), this is commonly used for custom blocks.
The issue
When a WP_Block is instantiated, the __construct method calls refresh_context_dependents(). This method performs sanitization of the context based on the block's usesContext definition.
Because openSubmenusOnClick is now missing from usesContext, it is filtered out during this process. Consequently, the backward compatibility function block_core_navigation_submenu_get_submenu_visibility() receives null, and the block defaults to 'hover' behavior.
Step-by-step reproduction instructions
Example code
$context = array( 'openSubmenusOnClick' => true );
$child = new WP_Block(
array(
'blockName' => 'core/navigation-link',
'attrs' => array( 'label' => 'Link', 'url' => '#' )
)
);
// Instantiate Submenu with Context.
$block = new WP_Block(
array(
'blockName' => 'core/navigation-submenu',
'attrs' => array( 'label' => 'Submenu', 'type' => 'custom' ),
'innerBlocks' => array( $child ),
),
$context
);
// Render.
$html = $block->render();
// Check for class.
var_dump( strpos( $html, 'open-on-click' ) !== false );
Actual result
The class is missing because the context was stripped.
Expected behavior
The open-on-click class should be present in the HTML output, ensuring backward compatibility for programmatic usage.
Screenshots, screen recording, code snippet
No response
Environment info
No response
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Please confirm which theme type you used for testing.
Description
In #74653, the
openSubmenusOnClickkey was removed from theusesContextarray inpackages/block-library/src/navigation-submenu/block.json.While internal rendering (via
inner_blocks) appears to handle context propagation, this removal breaks plugins that instantiate the block programmatically usingnew WP_Block( $attributes, $context ), this is commonly used for custom blocks.The issue
When a
WP_Blockis instantiated, the__constructmethod callsrefresh_context_dependents(). This method performs sanitization of the context based on the block'susesContextdefinition.Because
openSubmenusOnClickis now missing fromusesContext, it is filtered out during this process. Consequently, the backward compatibility functionblock_core_navigation_submenu_get_submenu_visibility()receivesnull, and the block defaults to'hover'behavior.Step-by-step reproduction instructions
Example code
Actual result
The class is missing because the context was stripped.
Expected behavior
The
open-on-clickclass should be present in the HTML output, ensuring backward compatibility for programmatic usage.Screenshots, screen recording, code snippet
No response
Environment info
No response
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Please confirm which theme type you used for testing.