Skip to content

Commit

Permalink
Navigation Link: Improve accessibility by removing tooltip in favor o…
Browse files Browse the repository at this point in the history
…f visual states
  • Loading branch information
himanshupathak95 committed Jan 14, 2025
1 parent 7850e1d commit 1bc424d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 27 deletions.
60 changes: 33 additions & 27 deletions packages/block-library/src/navigation-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ import {
TextControl,
TextareaControl,
ToolbarButton,
Tooltip,
ToolbarGroup,
} from '@wordpress/components';
import { displayShortcut, isKeyboardEvent } from '@wordpress/keycodes';
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';
import {
BlockControls,
InspectorControls,
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 @@ -579,27 +574,38 @@ 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
aria-label={ sprintf(
/* translators: %s: link status (Invalid or Draft) */
__( 'Navigation link text - %s' ),
isInvalid
? __( 'Invalid' )
: __( 'Draft' )
) }
>
{
// 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
10 changes: 10 additions & 0 deletions packages/block-library/src/navigation-link/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@
margin-bottom: $grid-unit-20;
margin-left: $grid-unit-20;
}

.wp-block-navigation-link__placeholder-text {
&.is-invalid {
--wp-underline-color: var(--wp--preset--color--vivid-red);
}

&.is-draft {
--wp-underline-color: var(--wp--preset--color--luminous-vivid-amber);
}
}
}

.wp-block-navigation-link__invalid-item {
Expand Down

0 comments on commit 1bc424d

Please sign in to comment.