-
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
Links that open in a new tab/window need to inform users a new tab/window will open #1577
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* 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( 'new-window-icon', className ); | ||
return ( | ||
<a { ...additionalProps } className={ classes } href={ href } target="_blank" rel={ rel }> | ||
{ children } | ||
<span className="screen-reader-text">{ __( '(opens in a new window)' ) }</span> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: Elsewhere in the WordPress codebase, this string is preceded with a translator comment Otherwise this could be: <span className="screen-reader-text">
{
/* translators: accessibility text */
__( '(opens in a new window)' )
}
</span> |
||
<Dashicon icon="external" /> | ||
</a> | ||
); | ||
} | ||
|
||
export default ExternalLink; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.new-window-icon { | ||
.dashicon { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A bit of horizontal margin might be nice, but is minor and can be addressed in a styling pass if necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. I'll make that happen. Good point with the noopener/etc. rels. |
||
width: 1.4em; | ||
height: 1.4em; | ||
margin: 0 .2em; | ||
vertical-align: top; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have checks for it, but: https://github.com/WordPress/gutenberg/blob/v0.3.0/.editorconfig#L9. Is there any way to add checks @nylen or @ntwb? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it's checked as part of the default stylelint config: |
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.
Per recommended CSS Naming guidelines, the default class name should be
components-external-link
https://github.com/WordPress/gutenberg/blob/master/docs/coding-guidelines.md#naming