Skip to content

Custom block stylesheet for the core/navigation-submenu block is not enqueued #66786

@germanfrelo

Description

@germanfrelo

Description

It's not possible to use a custom block stylesheet for the core/navigation-submenu block. The styles are not loaded on the front-end of the website. Instead, I have to put the submenu styles in the custom block stylesheet for the core/navigation block (for which the block stylesheet does works).

Step-by-step reproduction instructions

  1. Using a block theme, in the function.php file, add the code snippet below.
  2. Create a file named core-navigation-submenu.css in /assets/css/blocks/ (example) and add some styles like the example below.

Screenshots, screen recording, code snippet

In functions.php:

function themeslug_block_stylesheets() {
	// Add the block name (with namespace) for each style
	$blocks = array(
		// 'core/navigation',
		'core/navigation-submenu',
	);

	// Loop through each block and enqueue its styles
	foreach ( $blocks as $block ) {
		// Replace slash with hyphen for filename
		$slug = str_replace( '/', '-', $block );

		wp_enqueue_block_style( $block, array(
			'handle' => "themeslug-block-{$slug}",
			'src'    => get_theme_file_uri( "assets/css/blocks/{$slug}.css" ),
			'path'   => get_theme_file_path( "assets/css/blocks/{$slug}.css" )
		) );
	}
}

add_action( 'init', 'themeslug_block_stylesheets' );

In assets/css/blocks/core-navigation-submenu.css:

/**
 * Submenu Container (example)
 */

.wp-block-navigation .has-child .wp-block-navigation-submenu__toggle[aria-expanded="true"] ~ .wp-block-navigation__submenu-container,
.wp-block-navigation .has-child:not(.open-on-click):hover > .wp-block-navigation__submenu-container,
.wp-block-navigation .has-child:not(.open-on-click):not(.open-on-hover-click):focus-within > .wp-block-navigation__submenu-container {
	min-width: max-content;
}

Environment info

  • Wordpress version: 6.6.2
  • Gutenberg version: I don't know, the one that comes with WP 6.6.2? 18.5?
  • Active theme: a custom block child theme of a custom block parent theme from scratch
  • Browser: Google Chrome 130.0.6723.92 (arm64)
  • macMini M2 with macOS Sonoma 14.7.1

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Type] BugAn existing feature does not function as intended

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions