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

Adds aria-label to links that open in new windows #11063

Merged
merged 13 commits into from
Oct 30, 2018

Conversation

ryanwelcher
Copy link
Contributor

@ryanwelcher ryanwelcher commented Oct 25, 2018

Description

Adds an aria-lablel to the generated link when it is set to open in new window. Fixes #4450

How has this been tested?

Tested in Chrome for Mac OS
Ran npm run test

Types of changes

New feature (non-breaking change which adds functionality)

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

if ( opensInNewWindow ) {
format.attributes.target = '_blank';
format.attributes.rel = 'noreferrer noopener';
format.attributes[ 'aria-label' ] = `${ text } (opens in a new tab)`;
Copy link
Member

Choose a reason for hiding this comment

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

This should be translatable.

@ryanwelcher
Copy link
Contributor Author

@ocean90 I've updated the PR to address your feedback. Thanks for reviewing it !

@adamsilverstein adamsilverstein added the [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). label Oct 26, 2018
@adamsilverstein adamsilverstein added this to the 4.2 milestone Oct 26, 2018
if ( opensInNewWindow ) {
format.attributes.target = '_blank';
format.attributes.rel = 'noreferrer noopener';
format.attributes[ 'aria-label' ] = `${ text } (${ __( 'opens in a new tab' ) })`;
Copy link
Contributor

@mcsf mcsf Oct 29, 2018

Choose a reason for hiding this comment

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

This is still problematic from an i18n standpoint. Should be something like:

// translators: accessibility label for external links, where the argument is the link text
const label = sprintf( __( '%s (opens in a new tab)' ), text );

format.attributes[ 'aria-label' ] = label;

Also note that an empty text leads to a label that starts with whitespace. Could be handled by calling String#trim: sprintf( … ).trim().

Edit: see i18n package.

Copy link
Member

Choose a reason for hiding this comment

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

@mcsf How could the text be empty? How can you have a no text linked?

@ryanwelcher
Copy link
Contributor Author

@mcsf I've updated the PR based on your input. Thanks for the direction!

I've also made some changes to the createLinkFormat to better reflect the use of the 3rd parameter that was introduced in this PR.

Copy link
Contributor

@mcsf mcsf left a comment

Choose a reason for hiding this comment

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

I pushed afd0191 straight from GitHub. Assuming that tests fine, this looks good to go.

@youknowriad youknowriad dismissed ocean90’s stale review October 30, 2018 10:06

Should be better now.

@youknowriad youknowriad merged commit 489fe16 into WordPress:master Oct 30, 2018
@ryanwelcher ryanwelcher deleted the fix/a11y-4450 branch October 30, 2018 12:33
@aduth
Copy link
Member

aduth commented Nov 20, 2018

As raised at #11815 (comment), it seems the aria-label is including the full text of the RichText field in which its contained, when it seems like it ought to only contain the text of the link itself? Is that correct?

@ellatrix
Copy link
Member

I see no tests. 😕

@aduth
Copy link
Member

aduth commented Nov 26, 2018

As raised at #11815 (comment), it seems the aria-label is including the full text of the RichText field in which its contained, when it seems like it ought to only contain the text of the link itself? Is that correct?

Created issue at #12325

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants