Skip to content

Commit

Permalink
Navigation Link: Improve accessibility by removing non-interactive to…
Browse files Browse the repository at this point in the history
…oltips (#68628)

* Navigation Link: Replace missing link tooltip with ARIA label

* Navigation Link: Improve accessibility by removing tooltip in favor of visual states

* Navigation Link Block: Remove redundant aria-labels

* Navigation Link Block: Change the draft underline color from amber to red

* Restore original markup and span element.

* Adjust CSS.

* Remove extra line.

---------

Co-authored-by: himanshupathak95 <abcd95@git.wordpress.org>
Co-authored-by: afercia <afercia@git.wordpress.org>
  • Loading branch information
3 people authored Jan 29, 2025
1 parent 35ba7ef commit 6beab84
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 47 deletions.
54 changes: 25 additions & 29 deletions packages/block-library/src/navigation-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
TextControl,
TextareaControl,
ToolbarButton,
Tooltip,
ToolbarGroup,
} from '@wordpress/components';
import { displayShortcut, isKeyboardEvent } from '@wordpress/keycodes';
Expand Down Expand Up @@ -490,10 +489,6 @@ export default function NavigationLinkEdit( {
const placeholderText = `(${
isInvalid ? __( 'Invalid' ) : __( 'Draft' )
})`;
const tooltipText =
isInvalid || isDraft
? __( 'This item has been deleted, or is a draft' )
: __( 'This item is missing a link' );

return (
<>
Expand Down Expand Up @@ -533,9 +528,7 @@ export default function NavigationLinkEdit( {
{ /* eslint-enable */ }
{ ! url ? (
<div className="wp-block-navigation-link__placeholder-text">
<Tooltip text={ tooltipText }>
<span>{ missingText }</span>
</Tooltip>
<span>{ missingText }</span>
</div>
) : (
<>
Expand Down Expand Up @@ -578,27 +571,30 @@ export default function NavigationLinkEdit( {
{ ( isInvalid ||
isDraft ||
isLabelFieldFocused ) && (
<div className="wp-block-navigation-link__placeholder-text wp-block-navigation-link__label">
<Tooltip text={ tooltipText }>
<span
aria-label={ __(
'Navigation link text'
) }
>
{
// Some attributes are stored in an escaped form. It's a legacy issue.
// Ideally they would be stored in a raw, unescaped form.
// Unescape is used here to "recover" the escaped characters
// so they display without encoding.
// See `updateAttributes` for more details.
`${ decodeEntities( label ) } ${
isInvalid || isDraft
? placeholderText
: ''
}`.trim()
}
</span>
</Tooltip>
<div
className={ clsx(
'wp-block-navigation-link__placeholder-text',
'wp-block-navigation-link__label',
{
'is-invalid': isInvalid,
'is-draft': isDraft,
}
) }
>
<span>
{
// Some attributes are stored in an escaped form. It's a legacy issue.
// Ideally they would be stored in a raw, unescaped form.
// Unescape is used here to "recover" the escaped characters
// so they display without encoding.
// See `updateAttributes` for more details.
`${ decodeEntities( label ) } ${
isInvalid || isDraft
? placeholderText
: ''
}`.trim()
}
</span>
</div>
) }
</>
Expand Down
45 changes: 27 additions & 18 deletions packages/block-library/src/navigation-link/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,33 @@
background-image: none !important;

// Draw a wavy underline.
.wp-block-navigation-link__placeholder-text span {
$blur: 10%;
$width: 6%;
$stop1: 30%;
$stop2: 64%;

--wp-underline-color: var(--wp-admin-theme-color);

background-image:
linear-gradient(45deg, transparent ($stop1 - $blur), var(--wp-underline-color) $stop1, var(--wp-underline-color) ($stop1 + $width), transparent ($stop1 + $width + $blur)),
linear-gradient(135deg, transparent ($stop2 - $blur), var(--wp-underline-color) $stop2, var(--wp-underline-color) ($stop2 + $width), transparent ($stop2 + $width + $blur));
background-position: 0 100%;
background-size: 6px 3px;
background-repeat: repeat-x;

// Since applied to a span, it doesn't change the footprint of the item,
// but it does vertically shift the underline to better align.
padding-bottom: 0.1em;
.wp-block-navigation-link__placeholder-text {
span {
$blur: 10%;
$width: 6%;
$stop1: 30%;
$stop2: 64%;

--wp-underline-color: var(--wp-admin-theme-color);

background-image:
linear-gradient(45deg, transparent ($stop1 - $blur), var(--wp-underline-color) $stop1, var(--wp-underline-color) ($stop1 + $width), transparent ($stop1 + $width + $blur)),
linear-gradient(135deg, transparent ($stop2 - $blur), var(--wp-underline-color) $stop2, var(--wp-underline-color) ($stop2 + $width), transparent ($stop2 + $width + $blur));
background-position: 0 100%;
background-size: 6px 3px;
background-repeat: repeat-x;

// Since applied to a span, it doesn't change the footprint of the item,
// but it does vertically shift the underline to better align.
padding-bottom: 0.1em;
}

&.is-invalid,
&.is-draft {
span {
--wp-underline-color: var(--wp--preset--color--vivid-red);
}
}
}

// This needs extra specificity.
Expand Down

0 comments on commit 6beab84

Please sign in to comment.