Skip to content

Commit

Permalink
Navigation: Apply color classes to the navigation container element (#…
Browse files Browse the repository at this point in the history
…50968)

* Navigation: Apply color classes to the navigation container element

Co-authored-by: Maggie <3593343+MaggieCabrera@users.noreply.github.com>

* Also apply styles to the container

* fix php linting

* remove trailing comma

---------

Co-authored-by: Maggie <3593343+MaggieCabrera@users.noreply.github.com>
  • Loading branch information
scruffian and MaggieCabrera authored May 25, 2023
1 parent f373afe commit 330dac9
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,14 +517,43 @@ function render_block_core_navigation( $attributes, $content, $block ) {
'core/site-logo',
);

$block_styles = isset( $attributes['styles'] ) ? $attributes['styles'] : '';
$style = $block_styles . $colors['inline_styles'] . $font_sizes['inline_styles'];
$class = implode( ' ', $classes );

// If the menu name has been used previously then append an ID
// to the name to ensure uniqueness across a given post.
if ( isset( $seen_menu_names[ $nav_menu_name ] ) && $seen_menu_names[ $nav_menu_name ] > 1 ) {
$count = $seen_menu_names[ $nav_menu_name ];
$nav_menu_name = $nav_menu_name . ' ' . ( $count );
}

$wrapper_attributes = get_block_wrapper_attributes(
array(
'class' => $class,
'style' => $style,
'aria-label' => $nav_menu_name,
)
);

$container_attributes = get_block_wrapper_attributes(
array(
'class' => 'wp-block-navigation__container ' . $class,
'style' => $style,
)
);

$inner_blocks_html = '';
$is_list_open = false;
foreach ( $inner_blocks as $inner_block ) {
$is_list_item = in_array( $inner_block->name, $list_item_nav_blocks, true );

if ( $is_list_item && ! $is_list_open ) {
$is_list_open = true;
$inner_blocks_html .= '<ul class="wp-block-navigation__container">';
$inner_blocks_html .= sprintf(
'<ul %1$s>',
$container_attributes
);
}

if ( ! $is_list_item && $is_list_open ) {
Expand All @@ -546,23 +575,6 @@ function render_block_core_navigation( $attributes, $content, $block ) {
$inner_blocks_html .= '</ul>';
}

$block_styles = isset( $attributes['styles'] ) ? $attributes['styles'] : '';

// If the menu name has been used previously then append an ID
// to the name to ensure uniqueness across a given post.
if ( isset( $seen_menu_names[ $nav_menu_name ] ) && $seen_menu_names[ $nav_menu_name ] > 1 ) {
$count = $seen_menu_names[ $nav_menu_name ];
$nav_menu_name = $nav_menu_name . ' ' . ( $count );
}

$wrapper_attributes = get_block_wrapper_attributes(
array(
'class' => implode( ' ', $classes ),
'style' => $block_styles . $colors['inline_styles'] . $font_sizes['inline_styles'],
'aria-label' => $nav_menu_name,
)
);

$modal_unique_id = wp_unique_id( 'modal-' );

// Determine whether or not navigation elements should be wrapped in the markup required to make it responsive,
Expand Down

1 comment on commit 330dac9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 330dac9.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5082186584
📝 Reported issues:

Please sign in to comment.