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

Links that open in a new tab/window need to inform users a new tab/window will open #1577

Merged
merged 3 commits into from
Jul 18, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions components/external-link/index.js
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 );
Copy link
Member

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

return (
<a { ...additionalProps } className={ classes } href={ href } target="_blank" rel={ rel }>
{ children }
<span className="screen-reader-text">{ __( '(opens in a new window)' ) }</span>
Copy link
Member

Choose a reason for hiding this comment

The 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 translators: accessibility text. My main concern would be if omitting the translator comment would create a separate string entry in GlotPress (I'm not sure)

https://translate.wordpress.org/projects/wp/dev/fr/default?filters%5Bterm%5D=opens+in+a+new+window&filters%5Buser_login%5D=&filters%5Bstatus%5D=current_or_waiting_or_fuzzy_or_untranslated&filter=Filter&sort%5Bby%5D=priority&sort%5Bhow%5D=desc

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;
8 changes: 8 additions & 0 deletions components/external-link/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.new-window-icon {
.dashicon {
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
}
}
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

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

1 change: 1 addition & 0 deletions components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export { default as Button } from './button';
export { default as ClipboardButton } from './clipboard-button';
export { default as Dashicon } from './dashicon';
export { default as DropZone } from './drop-zone';
export { default as ExternalLink } from './external-link';
export { default as FormToggle } from './form-toggle';
export { default as FormTokenField } from './form-token-field';
export { default as IconButton } from './icon-button';
Expand Down
6 changes: 3 additions & 3 deletions editor/sidebar/post-excerpt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { connect } from 'react-redux';
* WordPress dependencies
*/
import { __ } from 'i18n';
import { PanelBody } from 'components';
import { ExternalLink, PanelBody } from 'components';

/**
* Internal Dependencies
Expand All @@ -28,9 +28,9 @@ function PostExcerpt( { excerpt, onUpdateExcerpt } ) {
placeholder={ __( 'Write an excerpt (optional)' ) }
aria-label={ __( 'Excerpt' ) }
/>
<a href="https://codex.wordpress.org/Excerpt" target="_blank">
<ExternalLink href="https://codex.wordpress.org/Excerpt">
{ __( 'Learn more about manual excerpts' ) }
</a>
</ExternalLink>
</PanelBody>
);
}
Expand Down