-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Conversation
…eLinkFormat function and addings some inline docs
if ( opensInNewWindow ) { | ||
format.attributes.target = '_blank'; | ||
format.attributes.rel = 'noreferrer noopener'; | ||
format.attributes[ 'aria-label' ] = `${ text } (opens in a new tab)`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be translatable.
@ocean90 I've updated the PR to address your feedback. Thanks for reviewing it ! |
if ( opensInNewWindow ) { | ||
format.attributes.target = '_blank'; | ||
format.attributes.rel = 'noreferrer noopener'; | ||
format.attributes[ 'aria-label' ] = `${ text } (${ __( 'opens in a new tab' ) })`; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
@mcsf I've updated the PR based on your input. Thanks for the direction! I've also made some changes to the |
There was a problem hiding this 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.
As raised at #11815 (comment), it seems the |
I see no tests. 😕 |
Created issue at #12325 |
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: