-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Links that open in a new tab/window need to inform users a new tab/wi…
…ndow will open (#1577) * Links that open in a new tab/window need to inform users a new tab/window will open ## Description Fixes #1105 by adding the external dashicon and the standard screen reader text too. ## How Has This Been Tested? I checked that the Excerpt external link which makes use of the new ExternalLink component contains the new icon and displays it correctly in major OSX browsers (Safari, Chrome, Firefox). I used the browser's inspector to confirm the screen-reader-text element gets properly added as well. ## Screenshots: ![Updated panel](http://files.urldocs.com/share/excerpt-block-updated/excerpt-bloc k-updated.png) ## Types of changes New feature (non-breaking change which adds functionality) ## Checklist: - [x] My code is tested. - [x] My code follows the WordPress code style. - [x] My code follows has proper inline documentation. (Other as basic components don't have inline documentation, just like this one) * 1105 - Fix formatting * 1105 - Changed the class name. Added translators: accessibility text comment
- Loading branch information
Showing
4 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
import { compact, uniq } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from 'i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Dashicon from '../dashicon'; | ||
import './style.scss'; | ||
|
||
function ExternalLink( { href, children, className, rel = '', ...additionalProps } ) { | ||
rel = uniq( compact( [ | ||
...rel.split( ' ' ), | ||
'external', | ||
'noreferrer', | ||
'noopener', | ||
] ) ).join( ' ' ); | ||
const classes = classnames( 'components-external-link', className ); | ||
return ( | ||
<a { ...additionalProps } className={ classes } href={ href } target="_blank" rel={ rel }> | ||
{ children } | ||
<span className="screen-reader-text"> | ||
{ | ||
/* translators: accessibility text */ | ||
__( '(opens in a new window)' ) | ||
} | ||
</span> | ||
<Dashicon icon="external" /> | ||
</a> | ||
); | ||
} | ||
|
||
export default ExternalLink; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.components-external-link { | ||
.dashicon { | ||
width: 1.4em; | ||
height: 1.4em; | ||
margin: 0 .2em; | ||
vertical-align: top; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters