Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation Link: Improve accessibility by removing non-interactive tooltips #68628

Merged
Merged
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
46 changes: 28 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,34 @@
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;
}


Copy link
Contributor Author

@himanshupathak95 himanshupathak95 Jan 29, 2025

Choose a reason for hiding this comment

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

@afercia Is the extra new line here intentional or can it be removed?

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

// This needs extra specificity.
Expand Down
Loading