Skip to content

Commit

Permalink
Navigation: Allow additional CSS classes (#18466)
Browse files Browse the repository at this point in the history
* Navigation: Allow additional CSS classses

Fixes a bug where additional CSS classes were not passed to the front-end.

* Don't add attribute if there are no styles.

* Update `$classes` assignment.

* Shorten variable name

* Fix things that broke during conflict resolution
  • Loading branch information
obenland authored Nov 15, 2019
1 parent fbd7fb8 commit 5d4a752
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions packages/block-library/src/navigation-menu/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,18 @@ function build_css_colors( $attributes ) {
* @return string Returns the post content with the legacy widget added.
*/
function render_block_navigation_menu( $attributes, $content, $block ) {
$colors = build_css_colors( $attributes );
$class_attribute = sprintf( ' class="%s"', esc_attr( $colors['css_classes'] ? 'wp-block-navigation-menu ' . $colors['css_classes'] : 'wp-block-navigation-menu' ) );
$style_attribute = $colors['inline_styles'] ? sprintf( ' style="%s"', esc_attr( $colors['inline_styles'] ) ) : '';
$colors = build_css_colors( $attributes );
$classes = array( 'wp-block-navigation-menu', $colors['css_classes'] );
if ( ! empty( $attributes['className'] ) ) {
$classes[] = $attributes['className'];
}

$classes = join( ' ', array_filter( $classes ) );

return sprintf(
implode(
"\n",
array(
'<nav%s%s>',
' %s',
'</nav>',
)
),
$class_attribute,
$style_attribute,
'<nav class="%1$s" %2$s>%3$s</nav>',
esc_attr( $classes ),
$colors['inline_styles'] ? sprintf( 'style="%s"', esc_attr( $colors['inline_styles'] ) ) : '',
build_navigation_menu_html( $block, $colors )
);
}
Expand Down

0 comments on commit 5d4a752

Please sign in to comment.