Skip to content

Commit

Permalink
Apply text decoration as CSS class
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Nov 9, 2021
1 parent d7d4d81 commit 9232704
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
1 change: 1 addition & 0 deletions packages/block-library/src/navigation/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"__experimentalTextTransform": true,
"__experimentalFontFamily": true,
"__experimentalTextDecoration": true,
"__experimentalSkipSerialization": [ "textDecoration" ],
"__experimentalDefaultControls": {
"fontSize": true
}
Expand Down
3 changes: 3 additions & 0 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ function Navigation( {
const isEntityAvailable =
! isNavigationMenuMissing && isNavigationMenuResolved;

const textDecoration = attributes.style?.typography?.textDecoration;

const blockProps = useBlockProps( {
ref: navRef,
className: classnames( className, {
Expand All @@ -202,6 +204,7 @@ function Navigation( {
'background-color',
backgroundColor?.slug
) ]: !! backgroundColor?.slug,
[ `has-text-decoration-${ textDecoration }` ]: textDecoration,
} ),
style: {
color: ! textColor?.slug && textColor?.color,
Expand Down
8 changes: 7 additions & 1 deletion packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,18 @@ function( $block ) {
if ( empty( $inner_blocks ) ) {
return '';
}

// Manually add block support text decoration as CSS class.
$text_decoration = _wp_array_get( $attributes, array( 'style', 'typography', 'textDecoration' ), null );
$text_decoration_class = sprintf( 'has-text-decoration-%s', $text_decoration );

$colors = block_core_navigation_build_css_colors( $attributes );
$font_sizes = block_core_navigation_build_css_font_sizes( $attributes );
$classes = array_merge(
$colors['css_classes'],
$font_sizes['css_classes'],
$is_responsive_menu ? array( 'is-responsive' ) : array()
$is_responsive_menu ? array( 'is-responsive' ) : array(),
$text_decoration ? array( $text_decoration_class ) : array()
);

$inner_blocks_html = '';
Expand Down
30 changes: 16 additions & 14 deletions packages/block-library/src/navigation/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,27 @@
padding: 0;
}

// Force links to inherit text decoration applied to navigation block.
// The extra selector adds specificity to ensure it works when user-set.
&[style*="text-decoration"] {
.wp-block-navigation-item,
.wp-block-navigation__submenu-container {
text-decoration: inherit;
// The following rules provide class based application of user selected text
// decoration via block supports.
&.has-text-decoration-underline .wp-block-navigation-item__content {
text-decoration: underline;

&:focus,
&:active {
text-decoration: underline;
}
}

a {
text-decoration: inherit;
&.has-text-decoration-line-through .wp-block-navigation-item__content {
text-decoration: line-through;

&:focus,
&:active {
text-decoration: inherit;
}
&:focus,
&:active {
text-decoration: line-through;
}
}

&:not([style*="text-decoration"]) {
&:not([class*="has-text-decoration"]) {
a {
text-decoration: none;

Expand Down Expand Up @@ -127,7 +129,7 @@
flex-grow: 1;

// Without this, the changing to zero on hover-out can cause wrapping and
// result in an invinite hover/hover-out loop.
// result in an infinite hover/hover-out loop.
white-space: nowrap;

// Right-align the chevron in submenus.
Expand Down

0 comments on commit 9232704

Please sign in to comment.