From 55de826613665721814c1fcf93fe8306b552b684 Mon Sep 17 00:00:00 2001 From: tomoki shimomura Date: Mon, 27 Jan 2025 23:34:58 +0900 Subject: [PATCH] Navigation Submenu: classname trailing spaces (#68880) Co-authored-by: shimotmk Co-authored-by: Mamaduka --- .../src/navigation-submenu/index.php | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/block-library/src/navigation-submenu/index.php b/packages/block-library/src/navigation-submenu/index.php index 0f560e2849fac2..016e708c3256e6 100644 --- a/packages/block-library/src/navigation-submenu/index.php +++ b/packages/block-library/src/navigation-submenu/index.php @@ -82,7 +82,6 @@ function render_block_core_navigation_submenu( $attributes, $content, $block ) { $font_sizes = block_core_navigation_submenu_build_css_font_sizes( $block->context ); $style_attribute = $font_sizes['inline_styles']; - $css_classes = trim( implode( ' ', $font_sizes['css_classes'] ) ); $has_submenu = count( $block->inner_blocks ) > 0; $kind = empty( $attributes['kind'] ) ? 'post_type' : str_replace( '-', '_', $attributes['kind'] ); $is_active = ! empty( $attributes['id'] ) && get_queried_object_id() === (int) $attributes['id'] && ! empty( get_queried_object()->$kind ); @@ -99,11 +98,29 @@ function render_block_core_navigation_submenu( $attributes, $content, $block ) { $open_on_hover_and_click = isset( $block->context['openSubmenusOnClick'] ) && ! $block->context['openSubmenusOnClick'] && $show_submenu_indicators; + $classes = array( + 'wp-block-navigation-item', + ); + $classes = array_merge( + $classes, + $font_sizes['css_classes'] + ); + if ( $has_submenu ) { + $classes[] = 'has-child'; + } + if ( $open_on_click ) { + $classes[] = 'open-on-click'; + } + if ( $open_on_hover_and_click ) { + $classes[] = 'open-on-hover-click'; + } + if ( $is_active ) { + $classes[] = 'current-menu-item'; + } + $wrapper_attributes = get_block_wrapper_attributes( array( - 'class' => $css_classes . ' wp-block-navigation-item' . ( $has_submenu ? ' has-child' : '' ) . - ( $open_on_click ? ' open-on-click' : '' ) . ( $open_on_hover_and_click ? ' open-on-hover-click' : '' ) . - ( $is_active ? ' current-menu-item' : '' ), + 'class' => implode( ' ', $classes ), 'style' => $style_attribute, ) );