-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
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.
- Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
- Yes
Please confirm which theme type you used for testing.
- Block
- Classic
- Hybrid (e.g. classic with theme.json)
- Not sure