Skip to content

Commit

Permalink
Navigation Submenu: classname trailing spaces (#68880)
Browse files Browse the repository at this point in the history
Co-authored-by: shimotmk <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
  • Loading branch information
3 people authored Jan 27, 2025
1 parent ca7573c commit 55de826
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions packages/block-library/src/navigation-submenu/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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,
)
);
Expand Down

0 comments on commit 55de826

Please sign in to comment.